在.NET中有一个线程调度器在长时间运行的线程?线程、中有、长时间、NET

2023-09-03 16:33:25 作者:世界与我无关

我们的情况是网络扫描仪。

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.

我希望能够安排大量的工作,但只具有任何给定的说十年,无论并行扫描主机的数量。即使我创造我自己的线程,许多回调和其它异步善良使用线程池和我最终耗尽资源。我应该看看MonoTorrent ...

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?

有一个线程池,我可以初始化到n长期生活主题?

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

似乎没有人注意到我提出了一些意见上的一些回应,所以我会在这里添加一对夫妇的事情。

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

在线程应该撤销这两个 优雅而有力。 主题应具有低优先级的离开GUI作出响应。 线程是长时间运行但为了(分钟),而不是令(天)。 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

有人可以解释为什么使用SmartThreadPool标机智公顷负效用?

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

推荐答案

在.NET 4中已集成的 任务并行库 。当你创建一个新的任务(新的线程抽象),你可以指定一个任务是长期运行。我们已经取得了很好的经验,与该(长为天,而不是分钟或小时)。

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).

您可以在.NET 2使用它很好,但有它实际上是一个扩展,检查 此处 。

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

在Visual Studio 2010中的调试并行应用程序基于任务(不是线程)已从根本上改善。它建议使用任务尽可能而非原纱。因为它可以让你在面向友好的方式更对象处理的并行性。

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.

 
精彩推荐
图片推荐