哦,大概明白你的意思了...其实也就是一个线程中参数传递的问题...给你提供回调的方法吧:使用回调方法检索数据,下面的示例演示了一个从线程中检索数据的回调方法。包含数据和线程方法的类的构造函数也接受代表回调方法的委托;在线程方法结束前,它调用该回调委托。using System; using System.Threading; public class ThreadWithState { private string boilerplate; private int value; private ExampleCallback callback; public ThreadWithState(string text, int number, ExampleCallback callbackDelegate) { boilerplate = text; value = number; callback = callbackDelegate; } public void ThreadProc() { Console.WriteLine(boilerplate, value); if (callback != null) callback(1); } } public class Example { public static void Main() { ThreadWithState tws = new ThreadWithState( "This report displays the number {0}.", 42, new ExampleCallback(ResultCallback) ); 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."); } public static void ResultCallback(int lineCount) { Console.WriteLine( "Independent task printed {0} lines.", lineCount); } }
*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
process.StartInfo.FileName = "ping.exe";
process.StartInfo.Arguments = "10.249.188.1";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
String resuilt = process.StandardOutput.ReadToEnd();
process.Close();resuilt 是线程标准输出结果. 或者说, 就是本来应该显示在cmd窗口里的那些字符.
using System.Threading;
public class ThreadWithState {
private string boilerplate;
private int value;
private ExampleCallback callback;
public ThreadWithState(string text, int number,
ExampleCallback callbackDelegate)
{
boilerplate = text;
value = number;
callback = callbackDelegate;
}
public void ThreadProc()
{
Console.WriteLine(boilerplate, value);
if (callback != null)
callback(1);
}
}
public class Example
{
public static void Main()
{
ThreadWithState tws = new ThreadWithState(
"This report displays the number {0}.",
42,
new ExampleCallback(ResultCallback)
); 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.");
} public static void ResultCallback(int lineCount)
{
Console.WriteLine(
"Independent task printed {0} lines.", lineCount);
}
}