In C# what is the recommended way of passing data between 2 threads?

后端 未结 9 861
长发绾君心
长发绾君心 2020-12-08 01:36

I have my main GUI thread, and a second thread running inside it\'s own ApplicationContext (to keep it alive, even when there is no work to be done). I want to call a method

9条回答
  •  长情又很酷
    2020-12-08 01:58

    In effect, you have created a poor man's version of a ThreadPool. Your second thread is just sitting there doing nothing and without a fair amount of work on your part, you can't just get it to do work for you. You would have to pass delegates into a queue that your thread then takes off and executes.

    Your best bet is to do what you intended and just use the .NET ThreadPool and give it work to do.

提交回复
热议问题