当前位置:网站首页>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);
}
}
}
}
边栏推荐
- Flutter3.0了,小程序不止于移动应用跨端运行
- Jerry's FM mode mono or stereo selection setting [chapter]
- ubuntu20安裝redisjson記錄
- 美国空军研究实验室《探索深度学习系统的脆弱性和稳健性》2022年最新85页技术报告
- Create applet from 0
- Jerry's ble exiting Bluetooth mode card machine [chapter]
- Open3d mesh filtering
- 树莓派设置wifi自动连接
- CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
- 23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
猜你喜欢

Variables, process control and cursors (MySQL)

Can the applet run in its own app and realize live broadcast and connection?

图形化工具打包YOLOv5,生成可执行文件EXE

Ubuntu20 installation redisjson record

Don't you know the relationship between JSP and servlet?

Household appliance industry under the "retail is king": what is the industry consensus?

Flutter3.0了,小程序不止于移动应用跨端运行

Mathematical induction and recursion

小程序能运行在自有App中,且实现直播和连麦?

体会设计细节
随机推荐
「小样本深度学习图像识别」最新2022综述
About Tolerance Intervals
华为小米互“抄作业”
[swift] learning notes (I) -- familiar with basic data types, coding styles, tuples, propositions
美国空军研究实验室《探索深度学习系统的脆弱性和稳健性》2022年最新85页技术报告
Room rate system - login optimization
Flink task exit process and failover mechanism
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
SQL Tuning Advisor一个错误ORA-00600: internal error code, arguments: [kesqsMakeBindValue:obj]
Shell programming basics
20.(arcgis api for js篇)arcgis api for js面采集(SketchViewModel)
HDU 4337 King Arthur&#39; S Knights it outputs a Hamiltonian circuit
cocos3——8.实现初学者指南
树莓派设置wifi自动连接
Flutter3.0, the applet is not only run across mobile applications
Mathematical induction and recursion
What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
The solution of unable to create servlet file after idea restart
Open3d mesh filtering
Don't you know the relationship between JSP and servlet?