I built a Testbox to learn something about threading in windows form applications. Silverlight and Java are providing the Dispatcher, which really helps when updating GUI Elements.
Code Samples: Declaration Class Delegate
public delegate void d_SingleString(string newText);
Create Thread
_thread_active = true;
Thread myThread = new Thread(delegate() { BackGroundThread(); });
myThread.Start();
Thread Function
private void BackGroundThread()
{
while (_thread_active)
{
MyCounter++;
UpdateTestBox(MyCounter.ToString());
Thread.Sleep(1000);
}
}
Delegating TextBox Updates
public void UpdateTestBox(string newText)
{
if (InvokeRequired)
{
BeginInvoke(new d_SingleString(UpdateTestBox), new object[] { newText });
return;
}
tb_output.Text = newText;
}
Is there a way to declare the Declaration of the Delate IN the BeginInvoke Method?!
something like
BeginInvoke(*DELEGATE DECLARATION HERE*, new object[] { newText });
Many thanks, rAyt