| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Renci.SshNet.Common |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Base class to encapsulates the results of an asynchronous operation that returns result. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 9 | | public abstract class AsyncResult<TResult> : AsyncResult |
| | | 10 | | { |
| | | 11 | | // Field set when operation completes |
| | | 12 | | private TResult _result; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Initializes a new instance of the <see cref="AsyncResult{TResult}"/> class. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="asyncCallback">The async callback.</param> |
| | | 18 | | /// <param name="state">The state.</param> |
| | | 19 | | protected AsyncResult(AsyncCallback asyncCallback, object state) |
| | 4299 | 20 | | : base(asyncCallback, state) |
| | 4299 | 21 | | { |
| | 4299 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Marks asynchronous operation as completed. |
| | | 26 | | /// </summary> |
| | | 27 | | /// <param name="result">The result.</param> |
| | | 28 | | /// <param name="completedSynchronously">if set to <see langword="true"/> [completed synchronously].</param> |
| | | 29 | | public void SetAsCompleted(TResult result, bool completedSynchronously) |
| | 4191 | 30 | | { |
| | | 31 | | // Save the asynchronous operation's result |
| | 4191 | 32 | | _result = result; |
| | | 33 | | |
| | | 34 | | // Tell the base class that the operation completed successfully (no exception) |
| | 4191 | 35 | | SetAsCompleted(exception: null, completedSynchronously); |
| | 4191 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Waits until the asynchronous operation completes, and then returns the value generated by the asynchronous o |
| | | 40 | | /// </summary> |
| | | 41 | | /// <returns> |
| | | 42 | | /// The invocation result. |
| | | 43 | | /// </returns> |
| | | 44 | | public new TResult EndInvoke() |
| | 4222 | 45 | | { |
| | 4222 | 46 | | base.EndInvoke(); // Wait until operation has completed |
| | 4190 | 47 | | return _result; // Return the result (if above didn't throw) |
| | 4190 | 48 | | } |
| | | 49 | | } |
| | | 50 | | } |