.NET events and libevent are not equivalent, though they share abstract concepts.
.NET events allow non-deterministic communication between CLR components. In C#, the component is an object - events are class members. In other languages, like F#, objects are not required. An event allows consumers to subscribe to notifications that occur on specific conditions in the source - a button is clicked, a download is complete, an exception occurred, etc. A few characteristics of .NET events:
- They're not tied to the underlying OS
- You can define events for any condition.
- They're not inherently asynchronous (the notifier and the notified aren't necessarily running at the same time, though they can be).
libevent allows non-deterministic, asynchronous communication between the OS and a consumer. This might feel similar to .NET events because they both invert control, but the mechanisms are very different.
- libevent uses OS-specific, non-blocking I/O(/dev/poll, kqueue, epoll) to improve performance. Your results will vary depending on the OS and mechanism you use.
- libevent event conditions include state changes in file descriptors, OS signals, or timeouts. You can't define arbitrary callback conditions.
- libevent is inherently asynchronous. The consumer doesn't block while waiting for the OS to return.
Should I try to learn libevent and
attempt to use it in custom .NET
server applications...?
If you're doing it for fun, sure. If you're doing it for work, probably not. libevent claims its biggest performance gains on *nix systems. Windows uses a different networking paradigm. The libevent developers are addressing these differences in version 2 but 2.0.5 is still a beta release.
In addition, .NET offers its own non-blocking I/O libraries including asynchronous sockets.