已public Task StartNew(Action<object> action, object state);重載為例 這里我用的是struct,也可以用class。都可以. static void Main(string[] arge) { string name = "AXM"; for (int i = 0; i <= 5; i++) { var t = System.Threading.Tasks.Task.Factory.StartNew(new Action<object>(UppercaseString), new a { inputString = name, i = i }); // 依舊是通過委托實例調(diào)用該方法 Console.WriteLine("task外:"+i); } Console.WriteLine("for外"); Console.ReadLine(); } private static void UppercaseString(object inputString) { var b = (a)inputString; Console.WriteLine("task內(nèi):"+b.i+b.inputString.ToUpper()); } public struct a { public int i { get; set; } public string inputString { get; set; } } |
|