Пример #1
0
        private void btnPara_Click(object sender, EventArgs e)
        {
            Console.WriteLine("--------- btnPara_Click开始");

            for (int i = 0; i < 10; i++)
            {
                ParameterizedThreadStart parameterizedThreadStart = x => {
                    Thread.Sleep(100);
                    Console.WriteLine("+++++++++++开始btnCalBack_Click线程 {0}", Thread.CurrentThread.ManagedThreadId);
                    Console.WriteLine("+++++++++++PbtnCalBack_Click输出 {0}", x);
                };
                ThreadExtesion thread = new ThreadExtesion();
                Func <string>  ss     = () => { return("a"); };

                string s = thread.ThreadCallBack(parameterizedThreadStart, ss, i);
                Console.WriteLine("+++++++++++带有返回值 {0}", s);
            }

            Console.WriteLine("--------- btnPara_Click结束");
        }
Пример #2
0
        private void btnCalBack_Click(object sender, EventArgs e)
        {
            Console.WriteLine("--------- btnCalBack_Click");

            for (int i = 0; i < 10; i++)
            {
                ParameterizedThreadStart parameterizedThreadStart = x => {
                    Thread.Sleep(100);
                    Console.WriteLine("+++++++++++开始btnCalBack_Click线程 {0}", Thread.CurrentThread.ManagedThreadId);
                    Console.WriteLine("+++++++++++PbtnCalBack_Click输出 {0}", x);
                };
                ThreadExtesion thread = new ThreadExtesion();
                thread.ThreadCallBack(parameterizedThreadStart, () =>
                {
                    Console.WriteLine("回调方法");
                }, i);
            }


            Console.WriteLine("--------- btnCalBack_Click");
        }