static void Test14() { Console.Clear(); //XTrace.Log.Level = LogLevel.Info; var server = new FileServer(); server.Log = XTrace.Log; server.Start(); var count = 0; Action <Object> func = s => { count++; var client = new FileClient(); try { client.Log = XTrace.Log; if (s + "" == "Test.exe") { client.Connect("127.0.0.1", server.Port); } else { client.Connect("::1", server.Port); } client.SendFile(s + ""); } finally { count--; client.Dispose(); } }; Task.Factory.StartNew(func, "Test.exe"); Task.Factory.StartNew(func, "NewLife.Core.dll"); Task.Factory.StartNew(func, "NewLife.Net.dll"); var file = @"F:\MS\cn_visual_studio_ultimate_2013_with_update_4_x86_dvd_5935081.iso"; if (File.Exists(file)) { Task.Factory.StartNew(func, file); } Thread.Sleep(500); while (count > 0) { Thread.Sleep(200); } server.Dispose(); }
private static void ExecuteMultipleActions() { var stopwatch = new Stopwatch(); stopwatch.Start(); var taskList = new List <Task>(); for (int i = 0; i < 10; i++) { taskList.Add(Task.Factory.StartNew(() => { var client = new FileClient(); client.Connect(); for (int x = 0; x < 50; x++) { RequestFile(client); SaveFile(client); } })); } Task.WaitAll(taskList.ToArray()); stopwatch.Stop(); Console.WriteLine(string.Concat("Total ", stopwatch.ElapsedMilliseconds, "ms")); }