当前位置:网站首页>C# Task拓展方法
C# Task拓展方法
2022-07-06 20:23:00 【望天hous】
TASK,英语单词,名词、动词,作名词的意思是“(困难的)任务,工作;(语言教学中的)活动”,作动词的意思是“派给某人(任务);对(手段或能力)要求极高”
如果单独想执行一个任务,忽略错误,此方法比较适合使用。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
public static class PublicTaskExtensions
{
static readonly Action<Task> IgnoreTaskContinuation = task => _ = task.Exception;
public static void Ignore(this Task task)
{
if (task.IsCompleted)
{
_ = task.Exception;
}
else
{
task.ContinueWith(IgnoreTaskContinuation,
CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
}
}
}
边栏推荐
猜你喜欢
[tools] basic concept of database and MySQL installation
亚像素级角点检测Opencv-cornerSubPix
【基于 RT-Thread Studio的CPK-RA6M4 开发板环境搭建】
21.(arcgis api for js篇)arcgis api for js矩形采集(SketchViewModel)
树莓派设置静态ip
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
About Confidence Intervals
Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
RestClould ETL 社区版六月精选问答
随机推荐
HDU ACM 4578 Transformation-&gt;段树-间隔的变化
如何自定义Latex停止运行的快捷键
CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
Opencv environment, and open a local PC camera.
Matlab Error (Matrix dimensions must agree)
树莓派设置wifi自动连接
Set WiFi automatic connection for raspberry pie
Appx code signing Guide
【安全的办公和生产力应用程序】上海道宁为您提供ONLYOFFICE下载、试用、教程
线性表的查找
Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
【C语言】 题集 of Ⅸ
Leetcode-02 (linked list question)
input_delay
Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]
[C language] question set of IX
Ubuntu20 installation redisjson record
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
About Confidence Intervals
Cryptography series: detailed explanation of online certificate status protocol OCSP