private static void ThreadTest() { LogThread("Start"); Order order = CreateOrderTest(); var product = order.Item as Product; if (product != null) { Operation operation = new AssemblyOperation(); operation.Log += LogThread; // synchroniczne // operation.Execute(product) // asynchroniczne //Thread thread1 = new Thread(() => operation.Execute(product)); //Thread thread2 = new Thread(() => operation.Execute(product)); //Thread thread3 = new Thread(() => operation.Execute(product)); //thread1.Start(); //thread2.Start(); //thread3.Start(); // Utworzenie wątków //for (int i = 0; i < 100; i++) //{ // Thread thread = new Thread(() => operation.Execute(product)); // thread.Start(); //} // Pula wątków for (int i = 0; i < 100; i++) { //ThreadPool.QueueUserWorkItem(Download, "http://www.vavatech.pl"); ThreadPool.QueueUserWorkItem(state => operation.Execute(product)); } } }
private static void TaskTest() { LogThread("Start"); Order order = CreateOrderTest(); var product = order.Item as Product; if (product != null) { Operation operation = new AssemblyOperation(); operation.Log += LogThread; //Task task = new Task(() => operation.Execute(product)); //task.Start(); for (int i = 0; i < 100; i++) { Task task = Task.Run(() => operation.Execute(product)); } } }