当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 关于线程的参数、“返回值”、及线程的中止

ASP.NET
ASP.NET实现数据图表a
ASP.NET实现数据图表1
Kbuilder.cs GIVE ME K
WebForm1.aspx K LINE YISHI GIEVE ME
ASP.NET实现数据图表b
today study 2005.03.03
ActiveX 组件复习笔记.1
Direct3D学习笔记(二)我们这里可以编写一个完全意义上的Direct3D程序了。
HttpContext类包含了个别HTTP请求的所有特定HTTP信息。
实现自定义分页(如:改变传统datagrid的分页显示、通过A-Z的字母来分页等)、选择...
关于Format字符串和Xml文件的解析(粗略)
wrox asp.net 2 beta preview study section 3
整合重复代码,生成自定义的列(组件)整合重复代码,生成自定义的datagrid(组件...
递归法提升密码穷举算法性能
如何用UltraEdit编译C#源程序
添加删除、更新按钮的提示确认信息,以及DATAGRID的添加、插入、更新、删除操作。
WebBrowser应用
My Composite in C#
DBForm的设计来源以及主要构想
.net中交易处理的解决方案

ASP.NET 中的 关于线程的参数、“返回值”、及线程的中止


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 129 ::
收藏到网摘: n/a

 

关于线程的参数(2.0)、“返回值”、及线程的中止


1.线程的参数:
有时候会想向辅助线程传递些信息,这里需要用到ParameterizedThreadStart 委托

示例:

        private void btRunThread_Click(object sender, EventArgs e)

        {

            Thread t = new Thread(new ParameterizedThreadStart(this.ThreadRun));

            t.Start(100);

        }

 

        private void ThreadRun(object o)

        {

            this.lbCompleted.Invoke((MethodInvoker)delegate { this.lbCompleted.Text = System.Convert.ToString(o); });

        }

 

2.通过代理可以大致实现类似功能,示例:

    class Program

    {

        static void Main(string[] args)

        {

            ThreadClass tc = new ThreadClass(new MyDlg(DlgMethod));

            Thread thread = new Thread(new ThreadStart(tc.ThreadRun));

            Console.WriteLine("second thread start");

            thread.Start();

            thread.Join();

            Console.WriteLine("second thread completed");

            Console.Read();       

        }


        private static void DlgMethod(int i)

        {

            Console.WriteLine("Second Thread Result:{0}", i);

        }

    }

 

    public delegate void MyDlg(int i);

 

    class ThreadClass

    {

        private MyDlg myDlg;

 

        public ThreadClass(MyDlg pDlg)

        {

            this.myDlg = pDlg;

        }

 

        public void ThreadRun()

        {

            int total = 0;

            for (int i = 0; i < 100; i++)

            {

                total += i;

            }

 

            if (myDlg != null)

            {

                myDlg(total);

            }

        }