如何运行async void函数c#?

2022-05-08

以下示例是关于Csharp中包含如何运行async void函数c#?用法的示例代码,想了解如何运行async void函数c#?的具体用法?如何运行async void函数c#?怎么用?如何运行async void函数c#?使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

[英]:how to run async void function c#源码类型:Csharp
// 100% working!!
async Task hello() // THIS IS FAKE ASYNC VOID FUNC
{
	List<Task> tasks = new List<Task>{
		new Task(console),
		new Task(console),
	};
	foreach(Task func in tasks)
	{
		func.Start();
	}
	Task empty = new Task(a);
	empty.Start();
	await empty; // DO NOTHING / EMPTINESS
	Console.WriteLine("Finished");
}
int num ;
void console() // RUNNING IN PARALLEL
{
	num++;
	for (int i = 0; i != 100 ; i++)
	{
		Console.WriteLine(i);
	}
	Console.WriteLine("console" + num.ToString() + " has been finished");
}
void a() // to kill the HELLO process
{
}
hello().Wait(); // running ASYNC FUNC

本文地址:https://www.itbaoku.cn/snippets/785458.html