Skip to content

Implementation of "DispatchQueue" in C# (something like swift)

License

Notifications You must be signed in to change notification settings

JafarH96/DispatchQueue

Repository files navigation

DispatchQueue

Implementation of a DispatchQueue for asynchronous code execution in an easy way, similar to the DispatchQueue in Swift language.

Usage

You can use the Main queue:

SerialQueue.main.Async((_) => {
	for (int i = 0; i < 100; i++)
	{
		Console.WriteLine($"From Main Queue {i}");
		Thread.Sleep(1000);
	}
});

Or create your own queue and use it separately:

SerialQueue myQueue = new SerialQueue();

myQueue.Async((_) => {
	for (int i = 0; i < 100; i++)
	{
		Console.WriteLine($"From My Queue {i}");
		Thread.Sleep(500);
	}
});

You can also run codes with a delay:

SerialQueue.main.AsyncAfter(milliseconds: 1000, (_) =>
{
	Console.WriteLine("After one second delay");
});

About

Implementation of "DispatchQueue" in C# (something like swift)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages