zoukankan      html  css  js  c++  java
  • 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()
                     {
                       
                        
                     }
               )
               );


            }

  • 相关阅读:
    Linux之网络ping(unknown host)故障及yum no more mirrors to try
    vim 中与编码有关的选项
    linux系统时间设定
    linux查看物理cpu的核数,个数,逻辑cpu的个数
    简单的api实现以及动态函数调用
    python2.7 urllib和urllib2
    四级菜单实现二
    四级菜单实现一
    url请求特殊字符转换
    tomcat配置
  • 原文地址:https://www.cnblogs.com/gaoxianzhi/p/7003063.html
Copyright © 2011-2022 走看看