コード例 #1
0
ファイル: TaskExtensionMethods.cs プロジェクト: sk8tz/ITask
 /// <summary>
 /// Converts the <see cref="ITask{TResult}"/> instance into a <see cref="Task{TResult}"/>.
 /// </summary>
 /// <param name="task">
 /// The task to convert.
 /// </param>
 /// <typeparam name="TResult">
 /// The type of the result of the task.
 /// </typeparam>
 /// <returns>
 /// The <see cref="Task{TResult}"/>.
 /// </returns>
 public static async Task <TResult> AsTask <TResult>(this ITask <TResult> task)
 {
     if (task == null)
     {
         throw new ArgumentNullException(nameof(task));
     }
     return(await task.ConfigureAwait(false));
 }
コード例 #2
0
ファイル: TaskExtensionMethods.cs プロジェクト: sk8tz/ITask
 /// <summary>
 /// Converts the <see cref="ITask"/> instance into a <see cref="Task"/>.
 /// </summary>
 /// <param name="task">
 /// The task to convert.
 /// </param>
 /// <returns>
 /// The <see cref="Task"/>.
 /// </returns>
 public static async Task AsTask(this ITask task)
 {
     if (task == null)
     {
         throw new ArgumentNullException(nameof(task));
     }
     await task.ConfigureAwait(false);
 }
コード例 #3
0
ファイル: TaskExtenstions.cs プロジェクト: qkb/WebApiClient
 /// <summary>
 /// 当请求异常时返回默认值
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="task"></param>
 /// <returns></returns>
 public static async Task <T> ExceptionThenDefault <T>(this ITask <T> task)
 {
     try
     {
         return(await task.ConfigureAwait(false));
     }
     catch (Exception)
     {
         return(default);
コード例 #4
0
        private static async ITask <int> UseGenericITaskAsync()
        {
            ITask <int> task = TaskAdapter <int> .Factory.StartNew(() => 43);

            var result = await task.ConfigureAwait(false);

            Console.WriteLine($"ITask<int> returned {result}");

            return(result);
        }
コード例 #5
0
 /// <summary>
 /// Converts the <see cref="ITask{TResult}"/> instance into a <see cref="Task{TResult}"/>.
 /// </summary>
 /// <param name="task">
 /// The task to convert.
 /// </param>
 /// <typeparam name="TResult">
 /// The type of the result of the task.
 /// </typeparam>
 /// <returns>
 /// The <see cref="Task{TResult}"/>.
 /// </returns>
 public static async Task <TResult> AsTask <TResult>(this ITask <TResult> task)
 {
     return(await task.ConfigureAwait(false));
 }
コード例 #6
0
 /// <summary>
 /// Converts the <see cref="ITask"/> instance into a <see cref="Task"/>.
 /// </summary>
 /// <param name="task">
 /// The task to convert.
 /// </param>
 /// <returns>
 /// The <see cref="Task"/>.
 /// </returns>
 public static async Task AsTask(this ITask task)
 {
     await task.ConfigureAwait(false);
 }
コード例 #7
0
        /// <summary>
        /// 保存到目标流
        /// </summary>
        /// <param name="response"></param>
        /// <param name="targetStream">流</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public static async Task SaveAsync(this ITask <HttpResponseMessage> response, Stream targetStream)
        {
            var res = await response.ConfigureAwait(false);

            await res.SaveAsync(targetStream).ConfigureAwait(false);
        }
コード例 #8
0
        /// <summary>
        /// 保存到目标文件
        /// </summary>
        /// <param name="response"></param>
        /// <param name="filePath">文件路径</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public static async Task SaveAsync(this ITask <HttpResponseMessage> response, string filePath)
        {
            var res = await response.ConfigureAwait(false);

            await res.SaveAsync(filePath).ConfigureAwait(false);
        }