c# usercontrol ,networkcomms3.0 Invoke总结

本文介绍了使用AccordionControl自定义控件的注意事项,包括如何避免页面重复加载和内存泄漏的问题;探讨了网络通信中客户端发送请求的最佳实践,避免同步问题;同时分享了修改GridView内值的方法及绑定字段模板技巧。

 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值