I would use a generic method for this:
private void DoWork<T>(ConcurrentQueue<T> queue,object objectType)
{
T outResult;// generic type
while(queue.TryDequeue(out outResult))
{
//do something
}
}
This way you can use any type of the ConcurrentQueue< T>.
And you can call it like: (same as the hardcoded veriant)
private void StartDoWork()
{
DoWork(myQueue, new TestData());
}
If you need the < T> to be of a specific basetype or interface, you can create constrains on it:
private void DoWork<T>(ConcurrentQueue<T> queue,object objectType) where T: IDisposable
{
T outResult;// generic type
while(queue.TryDequeue(out outResult))
{
//do something
outResult.Dispose();
}
}
The IDisposable is for example. So you're able to call the Dispose method (from the IDisposable)