C# threading pattern that will let me flush
Posted
by Jeff Alexander
on Stack Overflow
See other posts from Stack Overflow
or by Jeff Alexander
Published on 2010-03-18T21:37:59Z
Indexed on
2010/03/18
21:41 UTC
Read the original article
Hit count: 489
I have a class that implements the Begin/End Invocation pattern where I initially used ThreadPool.QueueUserWorkItem() to do thread my work.
I now have the side effect where someone using my class is calling the Begin (with callback) a ton of times to do a lot of processing so ThreadPool.QueueUserWorkItem is creating a ton of threads to do the processing. That in itself isn't bad but there are instances where they want to abandon the processing and start a new process but they are forced to wait for their first request to finish.
Since ThreadPool.QueueUseWorkItem() doesn't allow me to cancel the threads I am trying to come up with a better way to queue up the work and maybe use an explicit FlushQueue() method in my class to allow the caller to abandon work in my queue.
Anyone have any suggestion on a threading pattern that fits my needs?
© Stack Overflow or respective owner