本文介绍了使用参数化threadstart的多线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个线程是从相同的ParameterizedThreadStart创建的,
此委托封装了一个带有1个对象实参的方法,

我想使用传递给委托的不同参数执行每个线程.
但是我不知道该怎么做,例如,三个参数分别是a1,a2,a3.

该方法称为MakeGrey,我想执行3个线程t1,t2,t3,其中t1执行MakeGrey(a1),t2执行MakeGrey(a2),t3执行MakeGrey(a3).

你能告诉我怎么做吗?我知道我们必须在MakeGrey方法的开头有一个if语句,以检查InvokeRequired是否调用Invoke,但是调用此Invoke方法需要一个parameterizedthreadstart和一些参数,我不知道哪个参数传递给了Invoke,因为我如上所述,具有3个自变量a1,a2,a3.

希望你能理解我的坚持并帮助我!
非常感谢您的帮助!
谢谢!

I have 3 threads created from the same ParameterizedThreadStart,
this delegate encapsulates a method with 1 argument of object,

I want to execute each thread with different arguments passed into the delegate.
But I don''t know how to do, for example, the 3 arguments are a1, a2, a3.

The method is called MakeGrey, I want to execute 3 threads t1, t2, t3 with t1 executing MakeGrey(a1), t2 executing MakeGrey(a2), t3 executing MakeGrey(a3).

Could you tell me how to do it? I know we have to have an If statement at the beginning of the method MakeGrey to check if InvokeRequired to call Invoke, but calling this Invoke method requires a parameterizedthreadstart and some argument and I don''t know which argument is passed into Invoke because I have 3 arguments a1, a2, a3 as mentioned above.

Hope you understand what I''m being stuck at and help me!
Your help would be highly appreciated!
Thank you!

推荐答案


这篇关于使用参数化threadstart的多线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:50