threadpool

Thread control flow in async .NET Console program [duplicate]

不羁岁月 提交于 2019-12-02 00:44:50
This question already has an answer here: Async and await - difference between console, Windows Forms and ASP.NET 1 answer I was messing around with async/await in C# just to dig into some of the thread control flow and stumbled upon an unusual behavior that I would really appreciate clarification on. It would make sense that the execution after await continues on a calling thread even if the Task itself was executed in background. And in fact that's exactly what happens with, let's say, WPF. The following code: private async void Button_Click(object sender, RoutedEventArgs e) { Console

NotSupportedException on WaitHandle.WaitAll

霸气de小男生 提交于 2019-12-01 21:03:58
I am trying to execute the following code. The code tries to parallely download and save images. I pass a list of images to be downloaded. I wrote this in C# 3.0 and compiled it using .NET Framework 4 (VS.NET express edition). The WaitAll operation is resulting in a NotSupportedException (WaitAlll for multiple handles on a STA thread is not supported) everytime I try to run my program. I tried removing SetMaxThreads , but that didn't do any difference. public static void SpawnThreads(List<string> imageList){ imageList = new List<string>(imageList); ManualResetEvent[] doneEvents = new

ExecutorService which runs tasks in calling thread?

ぐ巨炮叔叔 提交于 2019-12-01 20:56:24
Are there any java.util.ExecutorService implementations which simply run all executed tasks in the calling thread? If this isn't included in Java by default, is there a library which contains an implementation like this? The only existing implementation I could find is SynchronousExecutorService - unfortunately buried somewhere in camel library. Pasting source code (without comments) here for future reference: package org.apache.camel.util.concurrent; import java.util.List; import java.util.concurrent.AbstractExecutorService; import java.util.concurrent.TimeUnit; public class

Single thread pool vs one thread pool per task

别说谁变了你拦得住时间么 提交于 2019-12-01 20:23:14
I want to use concurrency in Java to make requests to an online API, download and parse the response documents, and load the resulting data into a database. Is it standard to have one pool of threads in which each thread requests, parses, and loads? In other words, only one class implements Runnable . Or is it more efficient to have, say, three different pools of threads, with the first pool of threads making the requests and pushing them to a queue, the second pool of threads polling from the first queue, parsing, and pushing the parsed data to a second queue, and finally the third pool

Using threadpools/threading for reading large txt files?

こ雲淡風輕ζ 提交于 2019-12-01 20:22:07
On a previous question of mine I posted: I have to read several very large txt files and have to either use multiple threads or a single thread to do so depending on user input. Say I have a main method that gets user input, and the user requests a single thread and wants to process 20 txt files for that thread. How would I accomplish this? Note that the below isn't my code or its setup but just what the "idea" is. Example: int numFiles = 20; int threads = 1; String[] list = new String[20]; for(int i = 1; i < 21; i++){ list[i] = "hello" + i + ".txt";//so the list is a hello1.txt, hello2.txt, .

QNetworkAccessManager from ThreadPool

孤人 提交于 2019-12-01 19:35:56
问题 A very fundamental question. The documentation mentions that all methods in QNetworkAccessManager are reentrant. If so, is performing a get() method in a QRunnable without locks legal? My code would look something like this: class MyClass: public QRunnable { void run() { ... QNetworkAccessManager nam; QNetworkReply* reply = name.get(request) // No Read-write lock. ... } }; 回答1: From the Qt documentation: [...] a class is said to be reentrant if its member functions can [simultaneously] be

QNetworkAccessManager from ThreadPool

偶尔善良 提交于 2019-12-01 19:10:20
A very fundamental question. The documentation mentions that all methods in QNetworkAccessManager are reentrant. If so, is performing a get() method in a QRunnable without locks legal? My code would look something like this: class MyClass: public QRunnable { void run() { ... QNetworkAccessManager nam; QNetworkReply* reply = name.get(request) // No Read-write lock. ... } }; From the Qt documentation : [...] a class is said to be reentrant if its member functions can [simultaneously] be called safely from multiple threads, as long as each thread uses a different instance of the class. Since you

After FileSystemWatcher fires - Thread Pool or Dedicated thread?

别说谁变了你拦得住时间么 提交于 2019-12-01 18:33:14
I am about to implement the archetypal FileSystemWatcher solution. I have a directory to monitor for file creations, and the task of sucking up created files and inserting the into a DB. Roughly this will involve reading and processing 6 or 7, 80 char text files that appear at a rate of 150mS in bursts that occur every couple of seconds, and rarely a 2MB binary file will also have to be processed. This will most likely be a 24/7 process. From what I have read about the FileSystemWatcher object it is better to enqueue its events in one thread and then dequeue/process them in another thread. The

C#, IAsyncResult and the thread pool

廉价感情. 提交于 2019-12-01 18:25:17
I use the Action<object>.BeginInvoke() method, does this use the thread pool or not? I have the following C# code: List<FileHash> hashList1 = hashList.Where((x, ind) => ind % 2 == 0).ToList(); List<FileHash> hashList2 = hashList.Where((x, ind) => ind % 2 == 1).ToList(); Action<object> oddWork = CalcHash; Action<object> evenWork = CalcHash; IAsyncResult evenHandle = evenWork.BeginInvoke(hashList1, null, null); IAsyncResult oddHandle = oddWork.BeginInvoke(hashList2, null, null); evenWork.EndInvoke(evenHandle); oddWork.EndInvoke(oddHandle); Is the thread pool used behind the scenes or not? Or

How to get a second System.Thread.ThreadPool?

☆樱花仙子☆ 提交于 2019-12-01 17:54:32
If I use the ThreadPool in a nested way, my application hangs: ThreadPool.QueueUserWorkItem((state) => ThreadPool.QueueUserWorkItem(Action)); How to get a second and independent ThreadPool to achieve nesting? There is only one single ThreadPool - it's not something you can (or should) make more than one instance of in an application. I don't recommend doing this, but if you really wanted to, you could use multiple instances of your own ThreadPool implementation, such as SmartThreadPool . This would, technically, allow separate "thread pools". However, I suspect you're hanging due to a deadlock