M
MSDN
Hello,
Can anyone explain to me the specifics of how Control.BeginInvoke() is
implemented? Coming from a java background I expected it to behave somewhat
like SwingUtilities.invokeLater(). That is to say, I expected it append a
'unit of work' to the end of the message queue in a thread-safe fashion.
The problem is that I can't explain why the following code makes the entire
UI freeze. It appears that the infinite loop of BeginInvoke() methods is
preventing all other events (paint, etc) from being processed.
Form2.cs
public void Callback()
{
Debug.WriteLine("Callback #" + count++);
this.BeginInvoke( new MethodInvoker(this.Callback) );
}
Form1.cs
private void launchForm__Click(object sender, System.EventArgs e)
{
Form2 tmp = new Form2();
tmp.Visible = true;
tmp.Callback();
}
Is there an alternative to BeginInvoke() that would make this example work,
allowing the UI to paint and otherwise respond albeit still consuming
excessive CPU cycles? Does Control.BeginInvoke() have nothing to do with
the message queue?
I would appreciate any specific details of the Control.BeginInvoke()
implementation. "Executes the specified delegate asynchronously with the
specified arguments, on the thread that the control's underlying handle was
created on" is too ambiguous for me.
Thanks.
Darryl
Can anyone explain to me the specifics of how Control.BeginInvoke() is
implemented? Coming from a java background I expected it to behave somewhat
like SwingUtilities.invokeLater(). That is to say, I expected it append a
'unit of work' to the end of the message queue in a thread-safe fashion.
The problem is that I can't explain why the following code makes the entire
UI freeze. It appears that the infinite loop of BeginInvoke() methods is
preventing all other events (paint, etc) from being processed.
Form2.cs
public void Callback()
{
Debug.WriteLine("Callback #" + count++);
this.BeginInvoke( new MethodInvoker(this.Callback) );
}
Form1.cs
private void launchForm__Click(object sender, System.EventArgs e)
{
Form2 tmp = new Form2();
tmp.Visible = true;
tmp.Callback();
}
Is there an alternative to BeginInvoke() that would make this example work,
allowing the UI to paint and otherwise respond albeit still consuming
excessive CPU cycles? Does Control.BeginInvoke() have nothing to do with
the message queue?
I would appreciate any specific details of the Control.BeginInvoke()
implementation. "Executes the specified delegate asynchronously with the
specified arguments, on the thread that the control's underlying handle was
created on" is too ambiguous for me.
Thanks.
Darryl