c# thread method

前端 未结 5 1203
太阳男子
太阳男子 2020-12-10 02:02

If I have a

public void Method(int m)
{
  ...
}

how can I create a thread to this method?

Thread t = new Thread((Me

5条回答
  •  爱一瞬间的悲伤
    2020-12-10 02:53

    The method you are calling requires a parameter. Because it has one parameter and a return type of void you can use the following

    ThreadPool.QueueUserWorkItem(o => Method(m));
    

    You do not need to change the int to an object in the method signature using this method.

    There are advantages to using the ThreadPool over starting your own Thread manually. Thread vs ThreadPool

提交回复
热议问题