I have some question about using queues and threads. I already made researches, but I don't manage to understand the general functionnement.
What I want to do : I have a class, named "mTask", in which there are properties and a method, called "StartmTask". When I create a new mTask, I 开发者_开发技巧add it to a List .
And I want to process the mTask, when there are mTasks in the list. ( I have to launch a task on each free processor of the computer)
I don't understand how I should do... I think this is "simple" but I am actually lost. Is any one would be able to explain it as simply as possible ?
Thanks a lot, I keep searching, if I am not clear enough, or if you need more information, don't hesitate to ask.
Yowan
I think probably the best and simplest solution would be to put the mTask to the ThreadPool instead of an list which you would have to observe.
Have a look at the method
ThreadPool.QueueUserWorkItem
Example:
ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), )mTask);
private void DoWork(object o)
{
task = o;
}
If you use it, without any settings, the Threads are assigned to every cpu. You don't have to care about that.
精彩评论