Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
 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());
 }
Ejemplo n.º 9
0
 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());
 }
Ejemplo n.º 10
0
        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);
            }
        }