private delegate void CheckVersionNumber_CallBack (string str) ; // defined as a delegate for detecting a version
// version detects
Private void m_CheckVersionNumber ( String strVersionNumber) { the try { CheckVersionNumber_CallBack the CallBack = new new CheckVersionNumber_CallBack (Thread_CheckVersionNumber_CallBack); // the method of assigning delegate Thread = TH new new the thread (m_Thread_CheckVersionNumber); th.IsBackground = to true ; th.Start (the CallBack); // be transmitted to the child thread delegate } the catch(Exception EX) { MessageBox.Show ( " Error detection m_CheckVersionNumber version! " + 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); }
// main thread method Private void Thread_CheckVersionNumber_CallBack ( String STR) { IF ( the this .lstHttpEvent.InvokeRequired == to true ) { ReceiveMsgModel Msg = new new ReceiveMsgModel (Thread_CheckVersionNumber_CallBack); // Invokes the method name of the this .Invoke (Msg, new new Object [ ] STR {}); // not form the thread back to the form thread } the else { IF (STR == " to false " ) //Not up to date, true to the latest { MessageBox.Show ( " has a new version is released, please download the update in a timely manner! " ); The this .lstHttpEvent.SelectTab ( " tabVersion " ); } } }