blob: bb8ab130df9c6a79c8099ede00831447f3f437a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Common.Extensions
{
/// <summary>
/// Extension methods for <see cref="Process"/>.
/// </summary>
public static class ProcessExtensions
{
/// <summary>
/// Asynchronously wait for the process to exit.
/// </summary>
/// <param name="process">The process to wait for.</param>
/// <param name="timeout">The duration to wait before cancelling waiting for the task.</param>
/// <returns>A task that will complete when the process has exited, cancellation has been requested, or an error occurs.</returns>
/// <exception cref="OperationCanceledException">The timeout ended.</exception>
public static async Task WaitForExitAsync(this Process process, TimeSpan timeout)
{
using (var cancelTokenSource = new CancellationTokenSource(timeout))
{
await process.WaitForExitAsync(cancelTokenSource.Token).ConfigureAwait(false);
}
}
}
}
|