委托的begininvoke

http://blog.csdn.net/cml2030/article/details/2172854

 

http://blog.163.com/weizhiyong_111/blog/static/28597099200981145347563/

 

 //配置操作执行的委托
        /// <summary>
        /// 手机号信息配置执行委托
        /// </summary>
        /// <param name="statusString">包含操作失败的原因信息</param>
        /// <returns>True表示手机号信息配置成功,False表示手机号信息配置失败,失败原因在statusString参数中</returns>
        private delegate bool ConfigWarnInfoForTelNumsHandler(out string statusString);

子鼠 2014/6/26 20:00:37

  ConfigWarnInfoForTelNumsHandler configWarnInfoForTelNumsHandler = ConfigWarnInfoForTelNumsHandlerProcess;


子鼠 2014/6/26 20:00:49

 configWarnInfoForTelNumsHandler.BeginInvoke(out statusString, ConfigWarnInfoForTelNumsHandlerProcessCallBack, null);

子鼠 2014/6/26 20:01:12

 private bool ConfigWarnInfoForTelNumsHandlerProcess(out string statusString)
        {
            try
            {
                byte telNumberCount = (byte)0;
                string[] telInfoStringArray = new string[5];
                GenerateTelNumberCountAndTelInfoStringArray(out telNumberCount, telInfoStringArray);
                //ExcuteConfigWarnInfoOfTelNumber此函数下发指令
                if (CommandRequestExcutingManager.ExcuteConfigWarnInfoOfTelNumber(telNumberCount, telInfoStringArray))
                {
                    //将事件状态设置为非终止状态,从而导致线程受阻。
                    CommunicationManager.Instance.Commnication.ThreadSyncEventDictionary[DataAnalysisType.ConfigWarnInfoForTelNum].Reset();

                    //等待90秒,看是否能收到信号
                    if (CommunicationManager.Instance.Commnication.ThreadSyncEventDictionary[DataAnalysisType.ConfigWarnInfoForTelNum].WaitOne(130000))
                    {
                        if (telInfoConfigStatus)//配置成功之后,将telInfoConfigStatus置为true
                        {
                            //statusString = string.Empty;
                            statusString = "配置手机号码到短信模块成功";
                            return true;
                        }
                        else
                        {
                            statusString = "130秒内手机号信息配置失败!";
                            return false;
                        }
                    }
                    else//150秒没有响应
                    {
                        statusString = "[130秒内没有响应]与控制器通信失败,可能是接线松动,也可能是控制器电池耗尽等原因";
                        return false;
                    }
                }
                else
                {
                    statusString = "USB线连接异常,您可能需要重启软件,给您带来的不便,请谅解";
                    return false;
                }
            }
            catch (Exception ex)
            {
                LogService.LogManager.Instance.ProcessUIExceptionLog(ex);
                statusString = ex.Message;
                return false;
            }
        }

子鼠 2014/6/26 20:01:42

  /// <summary>
        /// 异步执行手机号信息配置回调函数
        /// </summary>
        /// <param name="ar">异步执行手机号信息配置的结果</param>
        private void ConfigWarnInfoForTelNumsHandlerProcessCallBack(IAsyncResult ar)
        {
            if (InvokeRequired)
            {
                Invoke(new AsyncCallback(ConfigWarnInfoForTelNumsHandlerProcessCallBack), ar);
            }
            else
            {
                ConfigWarnInfoForTelNumsHandler configWarnInfoForTelNumsAction = ((AsyncResult)ar).AsyncDelegate
                    as ConfigWarnInfoForTelNumsHandler;
                //让状态滚动条停止
                rItemMarqueeProgressBar.Stopped = true;
                 //调整UI上的显示
                grpTelConfig.Enabled = true;
                
                string failureStatus = string.Empty;
                //当使用BeginInvoke异步调用方法时,如果方法未执行完,EndInvoke方法就会一直阻塞,直到被调用的方法执行完毕
                if (configWarnInfoForTelNumsAction.EndInvoke(out failureStatus, ar))
                {
                    barStatusStaticItem.Caption = "预警手机号信息配置成功!";
                    barStatusStaticItem.Appearance.ForeColor = Color.Green;
                    BandTogvWarnValueInfo();
                    xtraTabControl1.SelectedTabPageIndex = 2;
                }
                else
                {
                    barStatusStaticItem.Caption = string.Format("预警手机号信息配置失败,{0}!", failureStatus);
                    barStatusStaticItem.Appearance.ForeColor = Color.Red;
                }
            }
        }
20:02:23
子鼠 2014/6/26 20:02:23


                CommunicationManager.Instance.Commnication.ThreadSyncEventDictionary[DataAnalysisType.ConfigWarnInfoForTelNum].Set();
posted @ 2014-06-26 19:57  ChuckLu  阅读(275)  评论(0编辑  收藏  举报