开发者

How do I multi-thread with private or public functions? C# 4.0

开发者 https://www.devze.com 2023-01-29 19:48 出处:网络
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>();

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消