Hey
I got a delegate function called like below
AudioDelegate AD = new AudioDelegate(this.Audio);
SetCallBack_Audio(AD)
GCHandle gAD = GCHandle.Alloc(AD);
void Audio()
{
//alot of stuff
this.txtStatus.text = "Recording"; // no work
messagebox.show("Recording"); // works
}
im doing the above but when the Audio event is fired i cant change the text of txtStatus at all, dont get an error message or anything, but the messagebox does work.
any idea's on how to fix this. im no c# boff so keep that in mind ;) might be something silly
Loading
Daniel van PletzenPosted Aug 6, 2007, 9:41 AM
AlanPosted Aug 6, 2007, 9:24 AM
The only reason I can think of why the MessageBox would show but the TextBox wouldn't update is if the callback is occurring on a different thread to your Form's 'user interface' thead. You can only (reliably) change items created on the UI thread from the UI thread itself. However, you can force the TextBox update onto that thread by calling its Invoke() method. For example (assumes .NET >= 2.0):
void Audio()
{
//a lot of stuff
EventHandler handler = new EventHandler(delegate {textStatus.Text = "Recording"};);
this.txtStatus.Invoke(handler);
Messagebox.Show("Recording");
}