AsyncDolls.TaskCompletionSource.TrySetResult C# (CSharp) Method

TrySetResult() public method

Attempts to transition the underlying Task into the TaskStatus.RanToCompletion state.
public TrySetResult ( ) : bool
return bool
        public bool TrySetResult()
        {
            return _tcs.TrySetResult(null);
        }
    }

Usage Example

Ejemplo n.º 1
0
 public static TaskAwaiter<int> GetAwaiter(this Process process)
 {
     var tcs = new TaskCompletionSource<int>();
     process.EnableRaisingEvents = true;
     process.Exited += (s, e) => tcs.TrySetResult(process.ExitCode);
     if (process.HasExited) tcs.TrySetResult(process.ExitCode);
     return tcs.Task.GetAwaiter();
 }