It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




已关闭8年。




是将全局变量用作参数的唯一方法,还是有一种更时尚的方法呢?

最佳答案

您可以使用ParameterizedThreadStart启动带有参数的线程。

例子:

Thread newThread = new Thread(myObj.DoMethod);
newThread.Start(parameter);

虽然,我通常最终会使用lambda
Thread newThread = new Thread(() => myObj.DoMethod(param1, param2, param3));
newThread.Start();

这可以更加方便,因为ParameterizedThreadStart将单个object作为参数。这很少是我想要的。

10-08 14:17