c# - 如何将多个参数传递给 C# 线程?

标签 c# multithreading

如何将多个参数传递给 C# 线程?任何示例将不胜感激。

最佳答案

假设你有一个方法:

void A(string a, int b) {}

这应该有效(.NET 2.0):

ThreadStart starter = delegate { A("word", 10); };
Thread thread = new Thread(starter);

thread.Start();

对于更高版本,以下(更短):

ThreadStart starter = () => A("word", 10);
Thread thread = new Thread(starter);

//or just...
//Thread thread = new Thread(() => A("word",10));

thread.start()

关于c# - 如何将多个参数传递给 C# 线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2490219/

相关文章:

c# - 将焦点设置到 datagridview 中新插入或更新的一行?

c# - Yield 的目的是什么,它是如何工作的?

c# - List索引和Array索引的区别

c# - 在更优化的 C# 中,如果这是正确的词 :++x or x++?

c++ - 线程输入问题

c# - 从使用由 C++ MFC 应用程序调用的异步的 C# COM 组件显示模态窗口

Java 线程安全的 LinkedHashMap 实现?

c# - 将泛型转换为接口(interface)类型 - 无法将类型为 'System.RuntimeType' 的对象转换为类型

java - java中的多线程持久队列

multithreading - 什么是事件驱动编程?