diff options
| author | Luke <luke.pulverenti@gmail.com> | 2015-03-19 13:21:35 -0400 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2015-03-19 13:21:35 -0400 |
| commit | 9926be0d9de688c04065c916e44ada4177b38a80 (patch) | |
| tree | 15338144a143948ffbee316641757e81489a7354 /MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs | |
| parent | b756e677d733992c2033bdd369980a37e17609e4 (diff) | |
| parent | 0564d454e5ad4f59702aa9022af6bb8fd064a9ff (diff) | |
Merge pull request #1043 from MediaBrowser/dev
3.0.5557.0
Diffstat (limited to 'MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs')
| -rw-r--r-- | MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 4d6cc1608..78dcea493 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -313,7 +313,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> - async void trigger_Triggered(object sender, EventArgs e) + async void trigger_Triggered(object sender, GenericEventArgs<TaskExecutionOptions> e) { var trigger = (ITaskTrigger)sender; @@ -340,11 +340,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// <summary> /// Executes the task /// </summary> + /// <param name="options">Task options.</param> /// <returns>Task.</returns> /// <exception cref="System.InvalidOperationException">Cannot execute a Task that is already running</exception> - public async Task Execute() + public async Task Execute(TaskExecutionOptions options) { - var task = ExecuteInternal(); + var task = ExecuteInternal(options); _currentTask = task; @@ -358,7 +359,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks } } - private async Task ExecuteInternal() + private async Task ExecuteInternal(TaskExecutionOptions options) { // Cancel the current execution, if any if (CurrentCancellationTokenSource != null) @@ -383,7 +384,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks try { - await ExecuteTask(CurrentCancellationTokenSource.Token, progress).ConfigureAwait(false); + var localTask = ScheduledTask.Execute(CurrentCancellationTokenSource.Token, progress); + + if (options != null && options.MaxRuntimeMs.HasValue) + { + CurrentCancellationTokenSource.CancelAfter(options.MaxRuntimeMs.Value); + } + + await localTask.ConfigureAwait(false); status = TaskCompletionStatus.Completed; } |
