Thread and ThreadStart

后端 未结 4 1708
名媛妹妹
名媛妹妹 2020-12-30 22:23

Both of the following lines work same. but is there any hidden difference? and which one should be preferred?

Thread t1 = new Thread(aMethod);

Thread t2 = n         


        
相关标签:
4条回答
  • 2020-12-30 22:48

    They are just the same but the second one allows you to use an extra parameter at the Thread starting method (well using ParametrizedThreadStart instead of ThreadStart).

    0 讨论(0)
  • 2020-12-30 22:57

    The c# compiler will transform the Thread t1 = new Thread(aMethod); statement to Thread t2 = new Thread(new ThreadStart(aMethod));

    0 讨论(0)
  • 2020-12-30 23:12

    There is no difference. Both lines are equal.

    0 讨论(0)
  • 2020-12-30 23:12

    A ThreadStart represents the method that executes on a Thread, so this is exactly the same thing.

    0 讨论(0)
提交回复
热议问题