我需要一个自定义的SynchronizationContext:
我需要这个,所以我可以单独测试一些线程代码,它们将在实际应用程序中与WinForm对话.
在我自己编写之前,我希望有人可以指出我的简单(和小)实现.
我有一个生产者,从资源中获取用户并将他们放入 ConcurrentQueue,然后我想做的是使用多个消费者并处理所有用户并从另一个资源中获取他们的信息。
public void Populate(IEnumerable<Users> users){
_queue.Enqueue(users);
// here single threaded
}
public void Process(){
// here i want this to be processed by multiple consumers
// say multiple threads so that I can finish processing them.
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我应该使用线程吗?任务?线程池?
我见过这个问题:C#相当于 Java ExecutorService.newSingleThreadExecutor(),或者:如何序列化对资源的多线程访问