G
Guest
Hello,
I'm still new to multithreading and I was just playing around with threads
and the UI and have a question.
I have this code in my form:
private void button3_Click(object sender, System.EventArgs e)
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}
private delegate void ThreadProcDelegate();
private void ThreadProc()
{
if(InvokeRequired)
{
Invoke(new ThreadProcDelegate(ThreadProc),null);
return;
}
this.Text = DateTime.Now.ToString("dd-MMM-yy");
}
Now, when the new thread starts, it correctly calls Invoke to run the method
because InvokeRequired returned true. After Invoke is called, InvokeRequired
is false.
My question is does InvokeRequired return true whenever you are in a non-gui
thread regardless if you are accessing any UI controls in the non-gui thread
or not?
Thanks,
-Flack
I'm still new to multithreading and I was just playing around with threads
and the UI and have a question.
I have this code in my form:
private void button3_Click(object sender, System.EventArgs e)
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}
private delegate void ThreadProcDelegate();
private void ThreadProc()
{
if(InvokeRequired)
{
Invoke(new ThreadProcDelegate(ThreadProc),null);
return;
}
this.Text = DateTime.Now.ToString("dd-MMM-yy");
}
Now, when the new thread starts, it correctly calls Invoke to run the method
because InvokeRequired returned true. After Invoke is called, InvokeRequired
is false.
My question is does InvokeRequired return true whenever you are in a non-gui
thread regardless if you are accessing any UI controls in the non-gui thread
or not?
Thanks,
-Flack