views:

190

answers:

4

Hi,

I'm looking for a good library, preferably in C#, which I can use in a windows service and it will handle all the multithreading functionality needed.

The service will run every x minutes, check a database for processes to call, and for each of them spawn a thread and run it.

Each thread should handle exceptions, logging and such.

Any suggestions?

Thanks.

+3  A: 

This is a bit tongue in cheek, but how about the .NET Framework? The System.Threading namespace has everything you need for this.

If you can use .NET 4, or the backport in the Rx Framework, the Task Parallel Library may make some of this a bit easier, as well, but even without that, the standard framework has everything you'd need.

Reed Copsey
Reed,I'm looking for a complete solution, a code implementation that uses System.Threading.No, I can't use 4.0 yet.Thanks.
anon2009
Can you use the Rx Framework? It includes a full backport of the Task Parallel library, which provides a huge amount of usability (much better than any third party lib I've seen, to date).
Reed Copsey
+2  A: 

Consider this project http://www.codeplex.com/smartthreadpool

Project Description

Smart Thread Pool is a thread pool written in C#. It is far more advanced than the .NET built-in thread pool. Here is a list of the thread pool features:

  • The number of threads dynamically changes according to the workload on the threads in the pool.
  • Work items can return a value.
  • A work item can be cancelled.
  • The caller thread's context is used when the work item is executed (limited).
  • Usage of minimum number of Win32 event handles, so the handle count of the application won't explode.
  • The caller can wait for multiple or all the work items to complete.
  • Work item can have a PostExecute callback, which is called as soon the work item is completed.
  • The state object, that accompanies the work item, can be disposed automatically.
  • Work item exceptions are sent back to the caller.
  • Work items have priority.
  • Work items group.
  • The caller can suspend the start of a thread pool and work items group.
  • Threads have priority.
  • Can run COM objects that have single threaded apartment.
  • Support Action and Func delegates.
  • Support for WindowsCE (limited)
  • The MaxThreads and MinThreads can be changed at run time.
  • Cancel behavior is imporved.
Fahad
Fahad,This is exactly what I'm looking for.I'll wait if someone lese has a better idea, otherwise I'll mark yours as the answer. Thanks
anon2009
A: 

If you need a scheduling library that has multi-threading support, I've used this before: Quartz.NET

http://quartznet.sourceforge.net/

Andy White
Can you give me n example on how you used it please?
anon2009
There's a good tutorial on the site, but you basically setup scheduling "triggers" (based on cron syntax) that determine when a job fires, then you associate specific jobs to the triggers. The Quartz.NET "Scheduler" handles all of the timing for you, and invokes your jobs at the set times. http://quartznet.sourceforge.net/tutorial/index.html
Andy White
We used it to kick off periodic database queries, which turn caused other actions to fire.
Andy White
Looks promising... I'll take a better look at it. It runs OK in Windows Server 2008.
anon2009
A: 

I'll write you one for $200 :). System.Threading is incredibly straight-forward.

Thread.Sleep should be about all you need...

Yoenhofen
If life was so easy!!!!
anon2009
Life is that easy. What about your application requires something more complicated than Thread.Sleep?
Yoenhofen