Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In .NET is there a thread scheduler for long running threads?

Our scenario is a network scanner.

It connects to a set of hosts and scans them in parallel for a while using low priority background threads.

I want to be able to schedule lots of work but only have any given say ten or whatever number of hosts scanned in parallel. Even if I create my own threads, the many callbacks and other asynchronous goodness uses the ThreadPool and I end up running out of resources. I should look at MonoTorrent...

If I use THE ThreadPool, can I limit my application to some number that will leave enough for the rest of the application to Run smoothly?

Is there a threadpool that I can initialize to n long lived threads?

[Edit] No one seems to have noticed that I made some comments on some responses so I will add a couple things here.

  • Threads should be cancellable both gracefully and forcefully.
  • Threads should have low priority leaving the GUI responsive.
  • Threads are long running but in Order(minutes) and not Order(days).

Work for a given target host is basically:

  For each test
    Probe target (work is done mostly on the target end of an SSH connection)
    Compare probe result to expected result (work is done on engine machine)
  Prepare results for host

Can someone explain why using SmartThreadPool is marked wit ha negative usefulness?

like image 377
LogicMagic Avatar asked Apr 22 '10 13:04

LogicMagic


1 Answers

In .NET 4 you have the integrated Task Parallel Library. When you create a new Task (the new thread abstraction) you can specify a Task to be long running. We have made good experiences with that (long being days rather than minutes or hours).

You can use it in .NET 2 as well but there it's actually an extension, check here.

In VS2010 the Debugging Parallel applications based on Tasks (not threads) has been radically improved. It's advised to use Tasks whenever possible rather than raw threads. Since it lets you handle parallelism in a more object oriented friendly way.

UPDATE
Tasks that are NOT specified as long running, are queued into the thread pool (or any other scheduler for that matter).
But if a task is specified to be long running, it just creates a standalone Thread, no thread pool is involved.

like image 139
ntziolis Avatar answered Nov 15 '22 12:11

ntziolis