WPF 实时绘图的逻辑
Posted shoutcharter
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF 实时绘图的逻辑相关的知识,希望对你有一定的参考价值。
实时绘图实际上是两个线程。外部线程直接用thread,只有到绘图那个逻辑才用绘图控件的mycanvas2.Dispatcher.Invoke。
或者说,INVOKE并不是开线程,只是一个绘图的委托而已。
主线程:
private void Read_UDP_Click(object sender, RoutedEventArgs e)
{
TCPRx mytcp = new TCPRx(" ", );
---------------------------------
error
---------------------------------
//Action<Canvas> updateAction = new Action<Canvas>(mytcp.readdata);
//updateAction.Invoke(this.FigureShow);
//this.FigureShow.Dispatcher.Invoke(updateAction,this.FigureShow);
//Action<Canvas, String> updateAction = new Action<Canvas, string>(mytcp.readdata);
//this.Dispatcher.BeginInvoke(updateAction, this.FigureShow, "");
new Thread(() =>
{
//this.FigureShow.Dispatcher.Invoke(new Action(() =>
{
while (true)
{
mytcp.readdata(this.FigureShow);
Thread.Sleep(10);
}
}
//)
//);
}).Start();
}
--------------------------------------------------------------------------------------------------------
绘图
--------------------------------------------------------------------------------------------------------
public void readdata(Canvas mycanvas2)
{
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint senderRemote = (EndPoint)sender;
state = new State(myconnect);
buffer = new byte[length];
//myconnect.BeginReceiveFrom(buffer, 0, length, SocketFlags.None, ref senderRemote, drawfigure, state);
//---- myconnect.Receive(buffer);//buffer, 0, length, SocketFlags.None, ref senderRemote, drawfigure, state);
string message = System.Text.Encoding.Default.GetString(buffer, 0, length);
string line = System.Text.Encoding.Default.GetString(buffer, 0, length);
if (string.IsNullOrEmpty(line.Trim()))
{
return;
}
//this.userName.Text = " 测试UI";
mycanvas2.Dispatcher.Invoke(
new Action(
delegate()
{
}
)
);
}
以上是关于WPF 实时绘图的逻辑的主要内容,如果未能解决你的问题,请参考以下文章