间接传替参数
public void test(string str1,string str2)
{
.......函数实现部分
}
public void dowork()
{
test(a,b);
}
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(dowork());
t.Start();
public void test(string str1,string str2)
{
.......函数实现部分
}
public void dowork()
{
test(a,b);
}
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(dowork());
t.Start();
解决方案 »
- 通过x:Class给ResourceDictionary内添加事件处理
- 关于<pages validateRequest="false" />-问题
- 【C#控制word】怎样获取range中除去最后一个word的range
- 两个WinForm类的调用函数问题
- 关于Repeater控件的用法!!求救!
- 天啊,<ItemTemplate>是正确的,但<EditItemTemplate>却错了,救命啊.
- lijipan 进来阿!!
- 急急急急急!引用程序集问题!
- 怎么样能刷新当前页面,象javascript的refresh一样
- VS.net奇怪的问题
- .net 中画表小问题。
- 自动增长字段使用时的困惑,请进来看看
向线程传递数据
ThreadStart 委托既没有参数也没有返回值。这意味着不可以使用需要参数的方法启动线程,或从方法中获得返回值。 为向线程传递数据,需要创建一个用来保持数据和线程方法的对象,如下面的[C#]
using System;
using System.Threading;// The ThreadWithState class contains the information needed for
// a task, and the method that executes the task.
//
public class ThreadWithState {
// State information used in the task.
private string boilerplate;
private int value; // The constructor obtains the state information.
public ThreadWithState(string text, int number) {
boilerplate = text;
value = number;
}
// The thread procedure performs the task, such as formatting
// and printing a document.
public void ThreadProc() {
Console.WriteLine(boilerplate, value);
}
}// Entry point for the example.
//
public class Example {
public static void Main() {
// Supply the state information required by the task.
ThreadWithState tws =
new ThreadWithState("This report displays the number {0}.", 42);
// Create a thread to execute the task, and then
// start the thread.
Thread t = new Thread(new ThreadStart(tws.ThreadProc));
t.Start();
Console.WriteLine("Main thread does some work, then waits.");
t.Join();
Console.WriteLine("Independent task has completed; main thread ends.");
}
}