public void TestCollection()
{
// create the wrapper
var asyncCollection = new BlockingCollectionWrapper<string>();
asyncCollection.FinishedEvent += FinishedEventHandler;
// make sure we dispose of it. this will stop the internal threads
using (asyncCollection)
{
// register a consuming action
asyncCollection.QueueConsumingAction = (producedItem) =>
{
Thread.Sleep(TimeSpan.FromSeconds(1));
Console.WriteLine(DateTime.Now + ": Consuming item: " + producedItem);
};
// start consuming
asyncCollection.Start();
// start producing
for (int i = 0; i < 10; i++)
{
Console.WriteLine(DateTime.Now + ": Produced item " + i);
asyncCollection.AddItem(i.ToString());
}
}
_testMutex.WaitOne();
Assert.True(asyncCollection.Finished);
}