码迷,mamicode.com
首页 > Windows程序 > 详细

WPF 实时绘图的逻辑

时间:2017-06-13 19:51:58      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:绘图   this   address   odi   update   click   error   state   private   

实时绘图实际上是两个线程。外部线程直接用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 实时绘图的逻辑

标签:绘图   this   address   odi   update   click   error   state   private   

原文地址:http://www.cnblogs.com/gaoxianzhi/p/7003063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!