Answers for "how to run async void function c#"

C#
3

how to run async void function c#

// 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
Posted by: Guest on May-07-2022
1

c# async and await example

Live async and await the demontration of the image described in the source link.
Posted by: Guest on May-02-2022

C# Answers by Framework

Browse Popular Code Answers by Language