zoukankan      html  css  js  c++  java
  • C#子线程执行完后,调用主线程的方法

    private delegate void CheckVersionNumber_CallBack(string str);//定义一个为委托 用于 检测版本

    //检测版本
    private
    void m_CheckVersionNumber(string strVersionNumber) { try { CheckVersionNumber_CallBack CallBack = new CheckVersionNumber_CallBack(Thread_CheckVersionNumber_CallBack); //把方法赋值给委托 Thread th = new Thread(m_Thread_CheckVersionNumber); th.IsBackground = true; th.Start(CallBack);//将委托传递到子线程中 } catch (Exception ex) { MessageBox.Show("m_CheckVersionNumber 检测版本时出错! " + strVersionNumber +" "+ ex.Message.ToString()); } }
     //子线程执行
     private void m_Thread_CheckVersionNumber(object obj)
     {
                string strVersionNumber = this.Text;
    
                clsWebSubmit objPost = new clsWebSubmit();
                string strUrl = clsConfig.CheckVersionNumberUrl;
                string strParam = "version_number=" + strVersionNumber;
                string strResult = objPost.m_PostSubmit(strUrl, strParam);
    
                Newtonsoft.Json.Linq.JObject jsonStr = Newtonsoft.Json.Linq.JObject.Parse(strResult);
                string str = jsonStr["result"].ToString().Trim();// 
    
                CheckVersionNumber_CallBack CallBack = obj as CheckVersionNumber_CallBack;//强转为委托
                CallBack(str);
     }
     //主线程的方法
     private void Thread_CheckVersionNumber_CallBack(string str)
     {
                if (this.lstHttpEvent.InvokeRequired == true)
                {
                    ReceiveMsgModel Msg = new ReceiveMsgModel(Thread_CheckVersionNumber_CallBack); //invokes为方法名
                    this.Invoke(Msg, new object[] { str });//不是窗体线程 则 回 窗体线程
                }
                else
                {
                    if (str == "false")//不是最新的, true为最新的
                    {
                        MessageBox.Show("已经有新版本发布,请及时下载更新! ");
                        this.lstHttpEvent.SelectTab("tabVersion");
                    }
                }
    }
  • 相关阅读:
    SQL中的数字格式化 (收藏)
    read about用法
    run into用法
    shoot for用法
    take off用法
    英语成语
    bring up用法
    satisfy with用法
    spend用法
    Linux环境进程间通信:共享内存
  • 原文地址:https://www.cnblogs.com/hailexuexi/p/11239032.html
Copyright © 2011-2022 走看看