I like the Distpatcher in the System.Windows.Threading namespace, and would like to use this object in a class library. However, since it was created for WPF and and seems to be specific to the UI, I feel like I’m abusing its intended purpose by using it in a class library.
I’m wondering if there exists some other class that serves the same purpose (creating a queue of work items for a thread) but is better intended for use in a class library. Essentially all I want to do is create a thread and, from another thread, asynchronously queue a bunch of delegates for it to run.
I could build something quite easily, but I would prefer to follow standard convention and use something that’s already proven. Thanks in advance.
BlockingCollectionis exactly what you need then. TheTakemethod blocks until an item appears in the queue which makes it ideal for these types of producer-consumer like scenarios.