C#多线程参数传递问题
我要在asp.net用多线程处理一段字符串,代码如下:
string content= "一串要处理的字符串 ";
System.Threading.Thread thread_split=new System.Threading.Thread(new System.Threading.ThreadStart(this.ClearHtml));//启动一个线程
//线程处理函数
private void ClearHtml()
{
}
请问我要如何把content这个的传值传递给该线程的处理函数ClearHtml()
------解决方案--------------------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. ");
}
}