c# usercontrol ,networkcomms3.0 Invoke总结

 1: accordionControl 添加了自定义控件页面 之后,切换到别的页面后,原先打开的页面对象还是存在的没有被销毁,再打开时重新引用即可

  private void accordionControlElement5_Click(object sender, EventArgs e)
        {
            SelectModelShowOnPanel("ad");
        }

    所以需要做一个判断
      if(ad==null) nd = new models.NowDataDemo(_neworkhelper);

 

2: networkcomms  使用过程中,客户端发送请求需要带返回包的,  并且是时钟不停请求的, 不要使用SendReceiveObject 方法,应为时钟和返回值不同步的话容易出现问题

 客户端发送:
  newTcpConnection.SendObject("ReqCount");
客户端接收:
NetworkComms.AppendGlobalIncomingPacketHandler<CountMsgContract>("ResCount", IncomingLineProductCoutRequest);
ResCount 相当于 路由,接收服务器端发送使用rescount 字符串的数据包

 3: 修改gridview内的值

   this.Invoke(new Action(() =>
            {
                resmsg.linename = "";
                resmsg.tiaocount = counttatmsg.TiaoCount;
                resmsg.firstcount = counttatmsg.FirstCount;
                resmsg.nextcount = counttatmsg.NextCount;
            }));

4:gridview 绑定字段模版

  public  class ResReceiveMsg :  INotifyPropertyChanged
    {
         public event PropertyChangedEventHandler PropertyChanged; 
         protected void OnPropertyChanged(string name) 
           {        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); }
       private string _linename="";
       private string _tiaocount="";
       private string _firstcount="";
       private string _nextcount="";
       /// <summary>
       ///
       /// </summary>
       public string linename
       {
           get{return _linename;}
           set{_linename=value;OnPropertyChanged("linename");}
       }
       /// <summary>
       ///
       /// </summary>
       public string tiaocount
       {
           get{return _tiaocount;}
           set{_tiaocount=value;OnPropertyChanged("tiaocount");}
       }
       /// <summary>
       ///
       /// </summary>
       public string firstcount
       {
           get{return _firstcount;}
           set{_firstcount=value;OnPropertyChanged("firstcount");}
       }
       /// <summary>
       ///
       /// </summary>
       public string nextcount
       {
           get{return _nextcount;}
           set{_nextcount=value;OnPropertyChanged("nextcount");}
       }
       public ResReceiveMsg(){}
    }

 使用这个模版的好处就是更新了数据源不用刷新控件 ,这个模版已继承了控件更新通知

原文地址:https://www.cnblogs.com/zuochanzi/p/7909566.html