// Method called and passed to user work item queue public void ThreadPoolCallback(Object threadContext) { HttpResponseMessage logResponse; string request; string content = null; // foreach url in the JArray make an http request foreach (var rec in Records) { try { // pull actual url from object in JArray request = String.Format(CultureInfo.InvariantCulture, rec.Value <string>("contentUri")); // pass request to HttpGet method logResponse = HttpGet(request, AuthResult); // if response is not null read body as string // then write to file specified using the one instance of Writer from the LogPull class if (logResponse != null) { content = logResponse.Content.ReadAsStringAsync().Result; if (content != null) { SafeWriter.WriteToFile(JArray.Parse(content), threadContext.ToString()); } else { Console.WriteLine("Error: Null response in thread"); } } } catch { // Just to not crash //Debug.WriteLine("Error when making request to content uri"); } } // Write that thread has finished and then set ManualReset Event // We write that it has finished to double check all threads finished later on Console.WriteLine("Thread {0} Done", threadContext); DoneEvent.Set(); }
protected async Task WorkLoop( CancellationToken cancellationToken, PauseToken pauseToken, Action action) { try { Running = true; while (!cancellationToken.IsCancellationRequested) { if (cancellationToken.IsCancellationRequested) { break; } // if pause token, spin here if (pauseToken.IsPaused) { if (PauseHolder(cancellationToken, pauseToken)) { break; } } action(); } } catch (ThreadAbortException e) { } finally { Running = false; DoneEvent.Set(); } }
/// <summary> /// Start the device in the current thread. Should be used by implementations of the <see cref="DeviceRunner.Start"/> method. /// </summary> /// <remarks> /// Initializes the sockets prior to starting the device with <see cref="Initialize"/>. /// </remarks> protected internal void Run() { EnsureNotDisposed(); Initialize(); FrontendSocket.ReceiveReady += (sender, args) => FrontendHandler(args); BackendSocket.ReceiveReady += (sender, args) => BackendHandler(args); DoneEvent.Reset(); IsRunning = true; _poller.ClearSockets(); _poller.AddSockets(new[] { FrontendSocket, BackendSocket }); TimeSpan timeout = TimeSpan.FromMilliseconds(PollingIntervalMsec); try { while (IsRunning) { _poller.Poll(timeout); } } catch (ZmqException) { // Swallow any exceptions thrown while stopping if (IsRunning) { throw; } } IsRunning = false; DoneEvent.Set(); }
public void ThreadPoolCallback(object threadContext) { FibOfN = Calculate(N); DoneEvent.Set(); }
// Wrapper method for use with thread pool. public void ThreadPoolCallback(ref MorphemeAssetProcessor.Result result) { Process(ref result); DoneEvent.Set(); }