Original Post
I'm having some issues trying to implement a worker thread in the background of a C# Windows Forms app. The worker thread - I'm trying to just have it update a Panel control every couple milliseconds (depending on what i set for Thread.Sleep). The problem for me has been that when I keep the Thread.Sleep high (like 500 milliseconds) the UI is responsive and normal, but when I set the Thread.Sleep low (like at 10) to get more frames per second. then the UI gets totally unresponsive and freezes. So I must be doing something wrong!
So I'm looking for any tips, I'm not sure that I'm handling the UI correctly. The app is basically a Panel control that is rendered using OpenGL and is refreshed constantly by a background thread. So I have a panel (this is the OpenGL panel that is refreshed constantly) on the left side of my form, and then just a bunch of standard controls on the right side (TextBox, Label, etc)
Thanks!
[Edited by - zmg2b6 on July 2, 2010 6:17:55 AM]
So I'm looking for any tips, I'm not sure that I'm handling the UI correctly. The app is basically a Panel control that is rendered using OpenGL and is refreshed constantly by a background thread. So I have a panel (this is the OpenGL panel that is refreshed constantly) on the left side of my form, and then just a bunch of standard controls on the right side (TextBox, Label, etc)
Thanks!
public partial class Form1 : Form { private ulong frameCount = 0; private delegate void VoidDelegate(); MyOpenGLPanel MyPanel = new MyOpenGLPanel(); public Form1() { InitializeComponent(); MyPanel.Dock = Dockstyle.Fill; panel1.Controls.Add(MyPanel); Thread t1 = new Thread(new ThreadStart(GoThread)); t1.IsBackground = true; t1.Start(); } private void GoThread() { while (true) { Thread.Sleep(500); RefreshOpenGLPanel(); } } private void RefreshOpenGLPanel() { if (InvokeRequired) { BeginInvoke(new VoidDelegate(RefreshOpenGLPanel)); } else { MyPanel.Refresh(); frameCount += 1; TextBox_FrameCount.Text = frameCount.ToString(); } } }[Edited by - zmg2b6 on July 2, 2010 6:17:55 AM]