Is ThreadPool in this scenario?

I have a thread that I launch every time a user scans a barcode.

In most cases, this is a fairly short stream. But sometimes it can take a very long time (waiting for a call to the GUI stream).

I read that it might be a good idea to use ThreadPool for this, and not just create your own thread for each scan.

But I also read that if ThreadPool ends with threads, it will just wait until some other thread exits (not OK for what I'm doing).

So how likely is it that I will run out of flow? And is the advantage of ThreadPool worth it? (When I scan it, it does not seem to take too long for the scan to “trigger” the flow logic.)

+3
source share
6 answers

It depends on what you mean by "very long time" and how common this scenario is.

The MSDN " Managed Thread Pool" topic offers good recommendations if you do not use thread pool threads:

There are several scenarios in which it is advisable to create and manage your own streams instead of stream stream streams:

  • You need a front end.
  • A stream requires a certain priority.
  • You have tasks that cause the thread to block for extended periods of time. The thread pool has the maximum number of threads, so a large number of blocked threads of the thread pool can start tasks.
  • . ThreadPool .
  • , , .
+4

- , threadpool - , .

+1

, , . , / . .NET Framework, . .

, ? . , ThreadPool.GetMaxThreads(). ( ) , .

http://msdn.microsoft.com/en-us/library/system.threading.threadpool.getmaxthreads.aspx

- , . threadpool , . , .NET. , , .

+1
0

, , , threadpool , . , . , .

, , 5 -. . 30-100 .

, , . , , , .

- , , , , 100- 1000 10 .

0

.net( ), : " ?"

, . , , , .

, , . , , , , . , , , . ... bam! . .

, , " ", , . . , .

(And, of course, with .net 2.0 you can set the maximum number of threads, so you can set the number if you absolutely need it.)

Others directed you to MSDN: “ “ Managed Thread Pool . I will repeat this direction because the article is good, but, in my opinion, it does not sell too much thread pool. :)

0
source

Source: https://habr.com/ru/post/1778359/


All Articles