public void Start() { // Создаем "слушателя" для указанного порта Listener = new TcpListener(IPAddress.Any, port); Listener.Start(); // Запускаем его //Client client = new Client(Listener.AcceptTcpClient()); // В бесконечном цикле while (true) { Client client = new Client(Listener.AcceptTcpClient()); ThreadPool.QueueUserWorkItem(new WaitCallback(ClientThread), Listener.AcceptTcpClient()); if (client.GetSecondParam() != null) { JobID jId = new JobID(jobIdCount, client.GetFirstParam(), client.GetSecondParam()); jobIdCount++; jobId.Add(jId); } if (client.GetSecondParam() == null) { jid = client.GetFirstParam(); } Thread.Sleep(1000); Worker worker = new Worker(jobId, jid); Thread worker_thread = new Thread(worker.Start); worker_thread.Start(); } }
public void Start() { while (true) { if ((JobIDs.Any()) && (num > 0)) { found = JobIDs.Where(m => m.Id == num).SingleOrDefault(); if (found == null) CreateJson(0); var webClient = new WebClient(); // Выполняем запрос по адресу и получаем ответ в виде строки var response = webClient.DownloadString(found.Par2); File.WriteAllText("temp" + num.ToString() + ".txt", response); file = new System.IO.StreamReader(@"temp" + num.ToString() + ".txt"); Thread.Sleep(1000); Thread readfile_thread = new Thread(ReadFile); mutexObj.WaitOne(); readfile_thread.Start(); mutexObj.ReleaseMutex(); } } }