I have this function in my Windows Form and now I'm trying to transfer my work to WPF,
After transferring I notice that InvokeRequired
and BeginInvoke
are not supported by WPF. I'm looking for the correct way to translate my function into WPF:
delegate void DisplayInvoker(string text, MessageType type);
private void DisplayinRichbox(string text, MessageType type = MessageType.Normal)
{
if (this.InvokeRequired) // not support by WPF
{
this.BeginInvoke(new DisplayInvoker(DisplayinRichbox), text, type); // Not support by WPF
return;
}
txt_Log.AppendText(String.Format("[{0}] {1}{2}\r\n",
DateTime.Now, type == MessageType.Incoming ? "<< " : type == MessageType.Outgoing ? ">> " : "", text));
txt_Log.ScrollToCaret(); // not support by WPF
}
Here is my Thread Loop in my main class :
while (bWaiting == true)
{
//System.Windows.Forms.Application.DoEvents(); // i comment it because i cant find equivalent in WPF
System.Threading.Thread.Sleep(15);
}