|
2 | 2 | using System.ComponentModel.Design; |
3 | 3 | using System.Net.Configuration; |
4 | 4 | using System.Threading; |
| 5 | +using System.Threading.Tasks; |
5 | 6 | using AzureWebFarm.OctopusDeploy.Infrastructure; |
6 | 7 | using Microsoft.WindowsAzure.ServiceRuntime; |
7 | 8 | using Serilog; |
@@ -58,26 +59,37 @@ public bool OnStart() |
58 | 59 | /// Call from the RoleEntryPoint.Run() method. |
59 | 60 | /// Note: This method is an infinite loop; call from a Thread/Task if you want to run other code alongside. |
60 | 61 | /// </summary> |
61 | | - public void Run() |
| 62 | + public async Task Run(CancellationToken token) |
62 | 63 | { |
63 | 64 | // Don't want to configure IIS if we are emulating; just sleep forever |
64 | | - if (RoleEnvironment.IsEmulated) |
65 | | - Thread.Sleep(-1); |
66 | | - |
67 | | - while (true) |
| 65 | + try |
68 | 66 | { |
69 | | - try |
| 67 | + if (RoleEnvironment.IsEmulated) |
70 | 68 | { |
71 | | - IisEnvironment.ActivateAppInitialisationModuleForAllSites(); |
| 69 | + while (!token.IsCancellationRequested) |
| 70 | + { |
| 71 | + await Task.Delay(100, token); |
| 72 | + } |
72 | 73 | } |
73 | | - catch (Exception e) |
| 74 | + |
| 75 | + while (!token.IsCancellationRequested) |
74 | 76 | { |
75 | | - Log.Warning(e, "Failure to configure IIS"); |
76 | | - } |
| 77 | + try |
| 78 | + { |
| 79 | + IisEnvironment.ActivateAppInitialisationModuleForAllSites(); |
| 80 | + } |
| 81 | + catch (Exception e) |
| 82 | + { |
| 83 | + Log.Warning(e, "Failure to configure IIS"); |
| 84 | + } |
77 | 85 |
|
78 | | - Thread.Sleep(TimeSpan.FromMinutes(10)); |
| 86 | + await Task.Delay(TimeSpan.FromMinutes(10), token); |
| 87 | + } |
| 88 | + } |
| 89 | + catch (TaskCanceledException) |
| 90 | + { |
79 | 91 | } |
80 | | - // ReSharper disable FunctionNeverReturns |
| 92 | + // ReSharper disable FunctionNeverReturns |
81 | 93 | } |
82 | 94 | // ReSharper restore FunctionNeverReturns |
83 | 95 |
|
|
0 commit comments