Invoke WPF
-
I have some code I'm trying to move to my view model. And it appears that my Invoke method does not work in it. I have the following code...
public delegate void SetTextCallBackSMT(string text);
Handing my serial port
string SMTData = SpSMT.ReadExisting();
if (SMTData.Contains("\r"))
{
modeSMT = ModeSMT.readLineSMTData;
}
else
{Invoke(new SetTextCallBackSMT(SetTextSMTDisplay), SMTData.ToString());
}
And my set text method....
private void SetTextSMTDisplay(string text)
{
this.RichTextBoxSMTDisplay.Text += text;
}The problem I'm having is that Invoke does not exist in the current context. I've tried adding forms name space. I've tried Dispatcher.Invoke, but I can't get that to work either. Any ideas?
-
I have some code I'm trying to move to my view model. And it appears that my Invoke method does not work in it. I have the following code...
public delegate void SetTextCallBackSMT(string text);
Handing my serial port
string SMTData = SpSMT.ReadExisting();
if (SMTData.Contains("\r"))
{
modeSMT = ModeSMT.readLineSMTData;
}
else
{Invoke(new SetTextCallBackSMT(SetTextSMTDisplay), SMTData.ToString());
}
And my set text method....
private void SetTextSMTDisplay(string text)
{
this.RichTextBoxSMTDisplay.Text += text;
}The problem I'm having is that Invoke does not exist in the current context. I've tried adding forms name space. I've tried Dispatcher.Invoke, but I can't get that to work either. Any ideas?
Most code in the view-model doesn't need to worry about threading issues. The binding to the view will usually take care of that for you. The only exception I'm aware of is if you're updating a collection from a background thread, where you may need to call the BindingOperations.EnableCollectionSynchronization[^] method to get it to work properly.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Most code in the view-model doesn't need to worry about threading issues. The binding to the view will usually take care of that for you. The only exception I'm aware of is if you're updating a collection from a background thread, where you may need to call the BindingOperations.EnableCollectionSynchronization[^] method to get it to work properly.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer