[C#] 匿名方法的方便和安全
2021-05-22 09:29
标签:tar read 安全 ons factor lin count begin line [C#] 匿名方法的方便和安全 标签:tar read 安全 ons factor lin count begin line 原文地址:https://www.cnblogs.com/catzhou/p/11194036.html static void Main(string[] args)
{
int count = 5;
//不安全写法
Task.Run(() =>
{
Thread.Sleep(1000);
Console.WriteLine("Main1_" + count);
});
//安全
Test1(count);
//安全
Task.Factory.StartNew((c) =>
{
Thread.Sleep(1000);
Console.WriteLine("Main2_" + c);
}, count);
//不安全
new Action(() =>
{
Thread.Sleep(1000);
Console.WriteLine("Main3_" + count);
}).BeginInvoke(null, null);
//安全
new Action