How do I multi-thread with private or public functions? C# 4.0
How do I multi-thread so that it will run private or public functions in the current class or di开发者_运维知识库fferent classes?
List<Action> tasks = new List<Action>();
tasks.Add(() => { ... do whatever });
tasks.Add(() => { ... do whatever });
tasks.Add(() => { ... do whatever });
tasks.Add(() => { ... do whatever });
System.Threading.Tasks.Parallel.Invoke(tasks.ToArray());
u can put this context in private or public method anywhere u like. and the execution context can also be both private and public.
精彩评论