C # multithreading

In multithreaded operating in, C # concurrent set of security ConcurrentBag replace List, ConcurrentDictionary replace Dictionary.

Recommended multithreaded code below, threadNum parallel threads, list for the collection to be processed before execution xx function when all the code executed.

Parallel.ForEach(list, new ParallelOptions() { MaxDegreeOfParallelism = threadNum }, (item, LoopState) =>
{
    //执行内容
});
xx();

 

Guess you like

Origin www.cnblogs.com/mldonkey/p/11245869.html