c# task run in background
来源:互联网 发布:达内java培训视频下载 编辑:程序博客网 时间:2024/06/05 01:01
1. Task.Run will start to run in background
2. Don't use breakpoint to debug, or all tasks will be interupted.
using System;using System.Collections.Generic;using System.Linq;using System.Threading;using System.Threading.Tasks;namespace SystemTasks{ class TestTask { public static async Task<int> A(int upper) { for (int i = 0; i < upper; ++i) { await Task.Delay(1000); Console.WriteLine("A: " + i); } return upper; } public static async Task<int> B(int upper) { for (int i = 0; i < upper; ++i) { await Task.Delay(1000); Console.WriteLine("B: " + i); } return upper; } public static async Task<int> C() { int xx = 0; var taskb = Task.Run(async () => { Console.WriteLine("Start B:"); int b = await B(10); Console.WriteLine("End B:"); return b; }); int a = await A(5); if (xx == 0) {// xx == 0, taskb will run in background even if the function has returned. return a; } else { await taskb; return taskb.GetAwaiter().GetResult(); } } static void Main() { C().GetAwaiter().GetResult(); Thread.Sleep(200000); //If using breakpoint here, all threads will be interupted return; } }}
0 0
- c# task run in background
- DEBUG in background task
- Run task when app enter background.
- Run matlab in server background
- 【Multitasking】Executing a Finite-Length Task in the Background
- Let's program run at background in linux/unix
- How can I run Perl system commands in the background
- APP Run In Background(App 的后台运行)
- APP Run In Background浅析(App 的后台运行)
- Parallel task in C# 4.0
- ios background task
- ios background task
- 后台 运行 background run
- linux-run command background
- Completing a Long-Running Task in the Background(在后台完成长时间运行的任务)
- Myeclips如果勾选了always run in background 该如何把进度条对话框调出
- Background Agent and Scheduled Task
- UWP -- Background Task 深入解析
- 错误:Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexP
- JSP获取异常信息的exception对象
- linux多屏配置文件 xorg.conf 官方配置文件说明翻译
- 31、Next Permutation
- oj1991: C语言实验——大小写转换
- c# task run in background
- pgsql批量修改table/view的owner
- 卡尔曼滤波的原理说明
- linux下/etc/hosts 和hostname文件的区别
- Javascript 面向对象编程(一):封装
- iOS常用的第三方库
- java模拟登陆正方教务管理系统
- nginx的定时器
- Java后台发送Post和get请求