示例#1
0
        public override void Run()
        {
            Trace.TraceInformation("WorkerRole is running");
            RotManager.TryKillTorIfRequired();

            try
            {
                this.RunAsync(this.cancellationTokenSource.Token).Wait();
            }
            catch (OperationCanceledException)
            {
                Trace.TraceInformation("WorkerRole.Run OperationCanceled");
            }
            catch (Exception ex)
            {
                Trace.TraceError("WorkerRole.Run Exception : " + ex.GetBaseException().ToString());
#if DEBUG
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
#endif
            }
            finally
            {
                RotManager.TryKillTorIfRequired();
                this.runCompleteEvent.Set();
            }
        }
示例#2
0
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            try
            {
                using (RotManager rot = new RotManager(GetRoleInstanceNumber()))
                {
                    while (!cancellationToken.IsCancellationRequested && rot.IsProcessOk())
                    {
                        await Task.Delay(30000, cancellationToken);
                    }
                }
            }
            catch (OperationCanceledException) { } // incluse TaskCanceledException
            catch (AggregateException) { }
            catch (Exception ex)
            {
                Trace.TraceError("WorkerRole.RunAsync Exception : " + ex.GetBaseException().ToString());
#if DEBUG
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
#endif
            }

            Trace.TraceInformation("WorkerRole.RunAsync : End");
        }