Esempio n. 1
0
 /// <summary>
 /// 类内部调用
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BKWorkNetMSG_DoWork(object sender, DoWorkEventArgs e)
 {
     try//dll里面,win7环境下无法释放端口
     {
         RecivedMSG MSGHandle = (RecivedMSG)e.Argument;
         while (!BKWorkNetMSG.CancellationPending)
         {
             byte[] rsv = udpc.Receive(ref ipedp);
             string msg = Encoding.ASCII.GetString(rsv);
             MSGHandle?.Invoke(msg);
             Application.DoEvents();
         }
         udpc.Close();
     }
     catch (Exception x)
     {
         MessageBox.Show(x.Message);
         if (udpc != null)
         {
             udpc.Close();
         }
     }
 }