2009-01-24

Announcing the release of Nito.Async

Nito Programs has released its first significant library as open-source:
http://www.codeplex.com/NitoAsync

This library makes it easier to develop framework-agnostic components that use the event-based asynchronous pattern.

What exactly this means - and why you might care - will be expounded on in the next few blog posts.

2 comments:

  1. Hi Stephen
    I found your library on the Codeplex, stress tested it with over 30 clients and one server, and is working like a charm. Grate work, thanks.
    In teh doc, it says, that various methods can not be initiated from a free-threading model. Does this mean that the library can not be used in a background thread or windows service?
    Most of my applications does not have a UI, so I am going to use the library in .NET DLLs, would this be ok. Any help is appriciated. Thanks again.

    Regards
    Sam

    ReplyDelete
  2. Hello, Sam -

    The socket classes in the Nito.Async library use the Event-Based Asynchronous Pattern. Part of this pattern is synchronizing the event callbacks with the originating thread. The problem with "threads without a synchronization context" is that they don't have a way to synchronize event callbacks.

    If you wish to use the Nito socket classes (or any other EBAP-based class) from a child thread, windows service, or console application, then you'll need to provide your own synchronization context for that thread. Nito.Async does provide a class that helps with this: ActionDispatcher. I know there isn't example code (this will be addressed in the next release), but hopefully the docs will get you started.

    The idea is that a child thread will call ActionDispatcher.Run to enter a message loop; the thread has a synchronization context as long as it is executing Run(). Other threads (or that same thread) may call ActionDispatcher.QueueAction to queue up work for that thread (i.e., a "ConnectToServer" delegate). Any EBAP components used by that thread's queued actions will use its sync context, so all their events end up getting queued in the same way. When it is time for the thread to exit, some thread calls ActionDispatcher.QueueExit, which causes Run to return.

    Note: ActionDispatcher should not be used by ThreadPool threads.

    Hope this is enough to get you started; if you have any questions, feel free to post to the CodePlex discussions or here.

    ReplyDelete