private void set_txt(object obj) { Thread.Sleep(2000); D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); this.Invoke(d_set_txt, "Current Thread ID:" + Thread.CurrentThread.ManagedThreadId.ToString() + " " + obj.ToString()); }
private int f_add(int a, int b) { D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); this.Invoke(d_set_txt, "ADD Start"); Thread.Sleep(3000); this.Invoke(d_set_txt, "ADD Complete"); return(a + b); }
private void set_txt_with_doc(object obj) { BsonDocument doc = (BsonDocument)obj; Thread.Sleep(Convert.ToInt16(doc["sleep"].ToString())); D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); this.Invoke(d_set_txt, "Current Thread ID:" + Thread.CurrentThread.ManagedThreadId.ToString() + " " + doc["txt"].ToString()); }
private void f_complete(IAsyncResult result) { D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); D_Add handler = (D_Add)((AsyncResult)result).AsyncDelegate; string str_result = handler.EndInvoke(result).ToString(); string str_state = result.AsyncState.ToString(); this.Invoke(d_set_txt, "Complte Async Result:" + str_result); this.Invoke(d_set_txt, "Complte ASync State:" + str_state); }
private void set_txt() { for (int i = 1; i < 10; ++i) { //这么调用会失败,产生错误“线程间操作无效” //this.txt_result.Text = i.ToString(); //需要用委托调用 D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); //用invoke 方法来达到线程间操作的目的 this.Invoke(d_set_txt, "Thread Set Text:" + i.ToString()); Thread.Sleep(500); } }
private void f_complete(IAsyncResult result) { D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); D_Add handler = (D_Add)((AsyncResult)result).AsyncDelegate; string str_result = handler.EndInvoke(result).ToString(); string str_state = result.AsyncState.ToString(); this.Invoke(d_set_txt, "Complte Async Result:"+str_result); this.Invoke(d_set_txt,"Complte ASync State:"+ str_state); }
private int f_add(int a, int b) { D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); this.Invoke(d_set_txt, "ADD Start"); Thread.Sleep(3000); this.Invoke(d_set_txt, "ADD Complete"); return a + b; }
private void set_txt_with_doc(object obj) { BsonDocument doc = (BsonDocument)obj; Thread.Sleep(Convert.ToInt16(doc["sleep"].ToString())); D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); this.Invoke(d_set_txt, "Current Thread ID:" + Thread.CurrentThread.ManagedThreadId.ToString() + " " +doc["txt"].ToString()); }
private void set_txt(object obj) { Thread.Sleep(2000); D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); this.Invoke(d_set_txt,"Current Thread ID:"+ Thread.CurrentThread.ManagedThreadId.ToString()+" "+ obj.ToString()); }
private void set_txt() { for (int i = 1; i < 10; ++i) { //这么调用会失败,产生错误“线程间操作无效” //this.txt_result.Text = i.ToString(); //需要用委托调用 D_SetTxt d_set_txt = new D_SetTxt(f_set_txt); //用invoke 方法来达到线程间操作的目的 this.Invoke(d_set_txt,"Thread Set Text:"+ i.ToString()); Thread.Sleep(500); } }