求~~~高人指点 线程传递参数的程序框架

俺们考试要考不会..求高人指点啊!!!老师给的参考程序usingSystem;usingSystem.Threading;classWork{//无参数方法publics... 俺们考试要考 不会..
求高人指点啊!!!
老师给的参考程序
using System;
using System.Threading;

class Work
{
//无参数方法
public static void DoWork()
{
Console.WriteLine("Static thread procedure.");
}

public int Data;

public void DoMoreWork()
{
Console.WriteLine("Instance thread procedure. Data={0}", Data);
}

//参数化方法
public static void DoWork(object data)
{
Console.WriteLine("Static thread procedure. Data='{0}'", data);
}

public void DoMoreWork(object data)
{
Console.WriteLine("Instance thread procedure. Data='{0}'", data);
}
}

class WorkTest
{
static void Main1()
{
//无参数方法
//public delegate void ThreadStart ()
// To start a thread using a static thread procedure, use the
// class name and method name when you create the ThreadStart
// delegate. Beginning in version 2.0 of the .NET Framework,
// it is not necessary to create a delegate explicityly.
// Specify the name of the method in the Thread constructor,
// and the compiler selects the correct delegate. For example:
//
//Thread newThread = new Thread(Work.DoWork);
//
ThreadStart threadDelegate = new ThreadStart(Work.DoWork);
Thread newThread = new Thread(threadDelegate);
newThread.Start();

// To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ThreadStart delegate. Beginning in version
// 2.0 of the .NET Framework, the explicit delegate is not
// required.
// ex:newThread = new Thread(w.DoMoreWork);
//
Work w = new Work();
w.Data = 42;
threadDelegate = new ThreadStart(w.DoMoreWork);
newThread = new Thread(threadDelegate);
newThread.Start();

//参数化方法
//public delegate void ParameterizedThreadStart (Object obj)

// To start a thread using a shared thread procedure, use
// the class name and method name when you create the
// ParameterizedThreadStart delegate.
//
Thread newThread1 = new Thread(new ParameterizedThreadStart(Work.DoWork));

// Use the overload of the Start method that has a
// parameter of type Object. You can create an object that
// contains several pieces of data, or you can pass any
// reference type or value type. The following code passes
// the integer value 42.
//
newThread1.Start(42);

// To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ParameterizedThreadStart delegate.
//
Work w1 = new Work();
newThread1 = new Thread(new ParameterizedThreadStart(w1.DoMoreWork));

// Pass an object containing data for the thread.
newThread1.Start("The answer.");
}
}

完全看不懂啊
框架只要写出类,函数名就可以了!!
展开
 我来答
天地英雄55
2009-01-02 · 超过73用户采纳过TA的回答
知道小有建树答主
回答量:346
采纳率:0%
帮助的人:226万
展开全部
using System;
using System.Threading; //引用线程的命名空间

class Work //Work是类名
{
//无参数方法
public static void DoWork() //函数名是DoWork功能是输出Static thread procedure
{
Console.WriteLine("Static thread procedure.");
}

public int Data;

public void DoMoreWork()函数名是DoMoreWork功能是输出“Instance thread procedure. Data=“和Data变量的值
{
Console.WriteLine("Instance thread procedure. Data={0}", Data);
}

//参数化方法
public static void DoWork(object data)函数名是DoWork 是上面同名函数的重载 功能是输出“Instance thread procedure. Data=“和Data变量的值
{
Console.WriteLine("Static thread procedure. Data='{0}'", data);
}

public void DoMoreWork(object data)函数名是DoMoreWork是上面同名函数的重载 功能是输出“Instance thread procedure. Data=“和Data变量的值
{
Console.WriteLine("Instance thread procedure. Data='{0}'", data);
}
}

class WorkTest //类名是 WorkTest
{
static void Main1() //入口主函数
{
//无参数方法
//public delegate void ThreadStart ()
// To start a thread using a static thread procedure, use the
// class name and method name when you create the ThreadStart
// delegate. Beginning in version 2.0 of the .NET Framework,
// it is not necessary to create a delegate explicityly.
// Specify the name of the method in the Thread constructor,
// and the compiler selects the correct delegate. For example:
//
//Thread newThread = new Thread(Work.DoWork);
//
ThreadStart threadDelegate = new ThreadStart(Work.DoWork); //实例化一个线程委托
Thread newThread = new Thread(threadDelegate);//实例化线程
newThread.Start();//线程开始运行

// To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ThreadStart delegate. Beginning in version
// 2.0 of the .NET Framework, the explicit delegate is not
// required.
// ex:newThread = new Thread(w.DoMoreWork);
//
Work w = new Work(); 实例化上面第一个类
w.Data = 42;给变量Data赋值
threadDelegate = new ThreadStart(w.DoMoreWork); //实例线程委托
newThread = new Thread(threadDelegate);//实例线程
newThread.Start();//线程执行

//参数化方法
//public delegate void ParameterizedThreadStart (Object obj)

// To start a thread using a shared thread procedure, use
// the class name and method name when you create the
// ParameterizedThreadStart delegate.
//
Thread newThread1 = new Thread(new 注释同上ParameterizedThreadStart(Work.DoWork));

// Use the overload of the Start method that has a
// parameter of type Object. You can create an object that
// contains several pieces of data, or you can pass any
// reference type or value type. The following code passes
// the integer value 42.
//
newThread1.Start(42);

// To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ParameterizedThreadStart delegate.
//
Work w1 = new Work();
newThread1 = new Thread(new ParameterizedThreadStart(w1.DoMoreWork)); 注释同上

// Pass an object containing data for the thread.
newThread1.Start("The answer.");
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式