This library provides a high-performance managed event loop implementation for .NET, inspired by the Node.JS event loop model.
The callbacks executed on the event loop are all executed on the same thread, so you don't have to deal with threading issues.
// create the event loop
var loop = new EventLoop();
// start it with a callback
loop.Start(() => Console.WriteLine("Event loop has started"));
// do stuff here, for example schedule another callback
loop.Schedule(() => Console.WriteLine("Another task"));
Console.WriteLine("Event loop is processing, press any key to quit");
Console.Read();
// we are done, dispose the loop so resources will be cleaned up
loop.Dispose();
The NLoop.Timing assembly provides timing related extension methods for the event loop.
Executes callback
once after timeout
.
// prints a message after 1 second
var cancel = loop.SetTimeout(() => Console.WriteLine("Something needs to happen right now!"), TimeSpan.FromSeconds(1));
// unless cancel is invoked within 1 second
cancel();
Executes callback
every timeout
.
// prints a message every second
var cancel = loop.SetInterval(() => Console.WriteLine("I'm alive!"), TimeSpan.FromSeconds(1));
// stop after cancel is invoked
cancel();
Copyright © 2013 Bert Willems and contributors
This project is licensed under MIT. Refer to LICENCE for more information.