public static void RunBackgroundJob(Action func, int intDelayMs = 0) { var thread = new Thread(() => { try { var host = new JobHost(); if (intDelayMs > 0) { host.DoWork(() => { //Initial delay Thread.Sleep(intDelayMs); func(); }); } else { host.DoWork(func); } } catch (Exception ex) { //TODO: Errorhandling throw ex; } }); thread.Start(); }
private void OnLogQueueStatsTimerElapsed(object state) { try { _jobHost.DoWork(() => { LogQueueStatistics(); }); } catch (Exception e) { SimpleTrace.Diagnostics.Fatal(e, "LogQueueStatistics error, Count {Count}", Interlocked.Increment(ref _maintainResourceGroupListErrorCount)); } }
public void WaitsForTaskToComplete() { var host = new JobHost(); var workTask = new Task(() => host.DoWork(new Task(() => { // Was getting inconsistent results with Thread.Sleep(100) for (int i = 0; i < 100; i++) { Thread.Sleep(1); } }))); var beforeStop = DateTime.UtcNow; workTask.Start(); while (workTask.Status != TaskStatus.Running) { Thread.Sleep(1); } host.Stop(false); var afterStop = DateTime.UtcNow; // If Stop didn't wait, we'd expect after to be less than 100 ms larger than beforeStop Assert.True((afterStop - beforeStop).TotalMilliseconds >= 100); }
public void ThrowsArgumentNullExceptionIfWorkIsNull() { var host = new JobHost(); var exception = Assert.Throws <ArgumentNullException>(() => host.DoWork(null)); Assert.Equal("work", exception.ParamName); }
public void ThrowsArgumentNullExceptionIfWorkIsNull() { var host = new JobHost(); var exception = Assert.Throws<ArgumentNullException>(() => host.DoWork(null)); Assert.Equal("work", exception.ParamName); }
public void EnsuresNoWorkIsDone() { var host = new JobHost(); var task = new Task(() => { throw new InvalidOperationException("Hey, this is supposed to be shut down!"); }); host.Stop(true); host.DoWork(task); }
public void DoesNotCallStartIfWorkIsAlreadyScheduledOrCompleted() { var tcs = new TaskCompletionSource<object>(); tcs.SetResult(null); var task = tcs.Task; var host = new JobHost(); Assert.DoesNotThrow(() => host.DoWork(task)); }
private static void OnTimerElapsed(object sender) { JobHost.DoWork(() => { using (var db = new AndacolContext()) { try { db.AskQuestions(); TimesScheduled++; } catch (Exception ex) { Debug.Print(ex.Message); } } }); }
private void OnTimerElapsed(object state) { try { _jobHost.DoWork(() => { MaintainResourceGroupLists(); _logCounter++; if (_logCounter % 5 == 0) { //log only every 5 minutes LogQueueStatistics(); _logCounter = 0; } }); } catch (Exception e) { SimpleTrace.Diagnostics.Fatal(e, "MainTainResourceGroupLists error, Count {Count}", Interlocked.Increment(ref _maintainResourceGroupListErrorCount)); } }
private static void OnTimerElapsed(object sender) { _jobHost.DoWork(() => { { //faz uma requisicao para mim msm. var client = new RestClient(ConfigurationManager.AppSettings["host"]); var request = new RestRequest("/Backend/ExecutarRodada", Method.GET); request.AddParameter("data", DateTime.Now.ToString("MM-dd-yyy")); request.RequestFormat = DataFormat.Xml; var queryResult = client.Execute(request); } { //faz uma requisicao para mim msm. var client = new RestClient(ConfigurationManager.AppSettings["host"]); var request = new RestRequest("/Backend/CalcularAssiduidade", Method.GET); request.RequestFormat = DataFormat.Xml; var queryResult = client.Execute(request); } }); }
private static void OnTimerElapsed(object sender) { _jobHost.DoWork(() => { AzureStatusService.ProcessAzureStatus(); }); }
private static void OnTimerElapsed(object sender) { _jobHost.DoWork(() => { /* What is it that you do around here */ }); }
private static void OnTimerElapsed(object sender) { _jobHost.DoWork(() => Matcher.matchPlayers()); }