您好,欢迎访问一九零五行业门户网

将参数传递给线程的 C# 程序

要使用线程,请在代码中添加以下命名空间 -
using system.threading;
首先,您需要在 c# 中创建一个新线程 -
thread thread = new thread(threaddemo);
上面,threaddemo是我们的线程函数。
现在将参数传递给线程 -
thread.start(str);
上面设置的参数是 -
string str = "hello world!";
示例让我们看看在 c# 中将参数传递给线程的完整代码。
实时演示using system;using system.threading;namespace sample { class demo { static void main(string[] args) { string str = "hello world!"; // new thread thread thread = new thread(threaddemo); // passing parameter thread.start(str); } static void threaddemo(object str) { console.writeline("value passed to the thread: "+str); } }}
输出value passed to the thread: hello world!
以上就是将参数传递给线程的 c# 程序的详细内容。
其它类似信息

推荐信息