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(); } }
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"); }