Пример #1
0
        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();
        }
Пример #2
0
 private void OnLogQueueStatsTimerElapsed(object state)
 {
     try
     {
         _jobHost.DoWork(() =>
         {
             LogQueueStatistics();
         });
     }
     catch (Exception e)
     {
         SimpleTrace.Diagnostics.Fatal(e, "LogQueueStatistics error, Count {Count}", Interlocked.Increment(ref _maintainResourceGroupListErrorCount));
     }
 }
Пример #3
0
            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);
            }
Пример #4
0
            public void ThrowsArgumentNullExceptionIfWorkIsNull()
            {
                var host = new JobHost();

                var exception = Assert.Throws <ArgumentNullException>(() => host.DoWork(null));

                Assert.Equal("work", exception.ParamName);
            }
Пример #5
0
            public void ThrowsArgumentNullExceptionIfWorkIsNull()
            {
                var host = new JobHost();

                var exception = Assert.Throws<ArgumentNullException>(() => host.DoWork(null));

                Assert.Equal("work", exception.ParamName);
            }
Пример #6
0
            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);
            }
Пример #7
0
            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);
            }
Пример #8
0
            public void DoesNotCallStartIfWorkIsAlreadyScheduledOrCompleted()
            {
                var tcs = new TaskCompletionSource<object>();
                tcs.SetResult(null);

                var task = tcs.Task;

                var host = new JobHost();

                Assert.DoesNotThrow(() => host.DoWork(task));
            }
Пример #9
0
            public void DoesNotCallStartIfWorkIsAlreadyScheduledOrCompleted()
            {
                var tcs = new TaskCompletionSource<object>();
                tcs.SetResult(null);

                var task = tcs.Task;

                var host = new JobHost();

                Assert.DoesNotThrow(() => host.DoWork(task));
            }
Пример #10
0
 private static void OnTimerElapsed(object sender)
 {
     JobHost.DoWork(() => {
         using (var db = new AndacolContext())
         {
             try
             {
                 db.AskQuestions();
                 TimesScheduled++;
             }
             catch (Exception ex) {
                 Debug.Print(ex.Message);
             }
         }
     });
 }
Пример #11
0
 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));
     }
 }
Пример #12
0
    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);
            }
        });
    }
Пример #13
0
            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);
            }
 private static void OnTimerElapsed(object sender)
 {
     _jobHost.DoWork(() => { AzureStatusService.ProcessAzureStatus(); });
 }
Пример #15
0
 private static void OnTimerElapsed(object sender)
 {
     _jobHost.DoWork(() => { /* What is it that you do around here */ });
 }
Пример #16
0
 private static void OnTimerElapsed(object sender)
 {
     _jobHost.DoWork(() => Matcher.matchPlayers());
 }