当前位置:网站首页>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);
}
}
}
}
边栏推荐
- Cocos2d-x Box2D物理引擎编译设置
- Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
- Numpy中排序操作partition,argpartition,sort,argsort
- input_ delay
- 【达梦数据库】备份恢复后要执行两个sql语句
- Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
- [untitled]
- cocos3——8.实现初学者指南
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
- [swift] learning notes (I) -- familiar with basic data types, coding styles, tuples, propositions
猜你喜欢
随机推荐
Under the tide of "going from virtual to real", Baidu AI Cloud is born from real
Matlab Error (Matrix dimensions must agree)
How to replace the backbone of the model
Ubuntu 20 installation des enregistrements redisjson
Cocos2d-x box2d physical engine compilation settings
CMB's written test - quantitative relationship
[untitled]
LAB1配置脚本
VHDL实现单周期CPU设计
Another million qubits! Israel optical quantum start-up company completed $15million financing
Appx code signing Guide
MOS transistor realizes the automatic switching circuit of main and auxiliary power supply, with "zero" voltage drop and static current of 20ua
密码学系列之:在线证书状态协议OCSP详解
1200.Minimum Absolute Difference
Jerry's RTC clock development [chapter]
Open3d mesh filtering
Code quality management
【C语言】 题集 of Ⅸ
CVPR 2022 best paper candidate | pip: six inertial sensors realize whole body dynamic capture and force estimation
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)