예제 #1
0
 public void AfterMyMothod3(IAsyncResult result)
 {
     AsyncResult async = (AsyncResult)result;
     MyScanMsgOperationLogicDelegate DelegateInstance = (MyScanMsgOperationLogicDelegate)async.AsyncDelegate;
 }
예제 #2
0
        internal void ReadResponseThread()
        {
            string strErr = string.Empty;

            try
            {
                AddSuccessToListView("线程1信息读取线程开始工作");

                for (; ;)
                {
                    if (workModel == 1)
                    {
                        //System.Threading.Thread.Sleep(new System.TimeSpan(0, 0, 0, 0, 200));
                        string response = string.Empty;
                        string res      = string.Empty;
                        lock (sp)
                        {
                            res = " ";
                            System.Text.StringBuilder b = new StringBuilder();
                            while (res.Length > 0)    //comport
                            {
                                //byte[] smsbuf = ss_port.Read(1);
                                //res = Encoding.ASCII.GetString(smsbuf);
                                //byte[] by_barcodes =new byte[20];
                                //sp.Read(by_barcodes,0,12);
                                //res = sp.ReadExisting();
                                //res = sp.ReadTo("\r\n");//COM2
                                res = sp.ReadTo("}");    //COM2
                                if (res.Length > 0)
                                {
                                    b.Append(res);
                                    break;
                                }
                            }
                            response = b.ToString();
                        }

                        if (response.Length > 0)
                        {
                            AddSuccessToListView("====================================================");
                            AddSuccessToListView("成功读取到扫描信息: " + response);
                            LogHelper.LogSimlpleString(DateTime.Now.ToString("G") + "成功读到扫描信息:" + response);
                            //启动线委托线程操作
                            string[] msgArray = null;
                            DataOperation.ChangeScannerData2StrLst(response, ref msgArray);

                            if (msgArray != null)
                            {
                                for (int i = 0; i < msgArray.Length; i++)
                                {
                                    string tmpMsg = (string)msgArray[i];
                                    MyScanMsgOperationLogicDelegate myMethod = new MyScanMsgOperationLogicDelegate(this.ScanMsgOperationLogic);
                                    myMethod.BeginInvoke(tmpMsg, new AsyncCallback(AfterMyMothod3), null);
                                }
                            }
                        }
                    }
                    System.Threading.Thread.Sleep(new System.TimeSpan(0, 0, 0, 0, 30));
                }
            }
            catch (ThreadAbortException e)
            {
                strErr = "读取信息ThreadAbortException:" + e.Message;
                AddErrToListView(strErr);
                LogHelper.LogSimlpleString(strErr);;
            }
            catch (Exception ex)
            {
                strErr = "读取信息出现异常:" + ex.Message;
                AddErrToListView(strErr);
                LogHelper.LogSimlpleString(strErr);
            }
        }