Search Results

Search found 215 results on 9 pages for 'threadpool'.

Page 2/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • Using ThreadPool.QueueUserWorkItem - thread unexpectedly exits

    - by alex
    I have the following method: public void PutFile(string ID, Stream content) { try { ThreadPool.QueueUserWorkItem(o => putFileWorker(ID, content)); } catch (Exception ex) { OnPutFileError(this, new ExceptionEventArgs { Exception = ex }); } } The putFileWorker method looks like this: private void putFileWorker(string ID, Stream content) { //Get bucket name: var bucketName = getBucketName(ID) .ToLower(); //get file key var fileKey = getFileKey(ID); try { //if the bucket doesn't exist, create it if (!Amazon.S3.Util.AmazonS3Util.DoesS3BucketExist(bucketName, s3client)) s3client.PutBucket(new PutBucketRequest { BucketName = bucketName, BucketRegion = S3Region.EU }); PutObjectRequest request = new PutObjectRequest(); request.WithBucketName(bucketName) .WithKey(fileKey) .WithInputStream(content); S3Response response = s3client.PutObject(request); var xx = response.Headers; OnPutFileCompleted(this, new ValueEventArgs { Value = ID }); } catch (Exception e) { OnPutFileError(this, new ExceptionEventArgs { Exception = e }); } } I've created a little console app to test this. I wire up event handlers for the OnPutFileError and OnPutFileCompleted events. If I call my PutFile method, and step into this, it gets to the "//if the bucket doesn't exist, create it" line, then exits. No exception, no errors, nothing. It doesn't complete (i've set breakpoints on my event handlers too) - it just exits. If I run the same method without the ThreadPool.QueueUserWorkItem then it runs fine... Am I missing something?

    Read the article

  • C# ThreadPool QueueUserWorkItem Synchronization

    - by ikurtz
    Greetings, I am employing ThreadPool.QueueUserWorkItem to play some sound files and not hanging up the GUI while doing so. It is working but has an undesirable side effect. While the QueueUserWorkItem CallBack Proc is being executed there is nothing to stop it from starting a new thread. This causes the samples in the threads to overlap. How can I make it so that it waits for the already running thread to finish running and only then run the next request? Thanks in advance :)

    Read the article

  • C# multi CPU for ThreadPool.QueueUserWorkItem

    - by ikurtz
    I have a program that uses: ThreadPool.QueueUserWorkItem(new WaitCallback(FireAttackProc), fireResult); On Windows7 and Vista it works fine. When I try to run it on XP the result is a bit different from the others. I was just wondering in order to execute QueueUserWorkItem properly do I need a dual CPU system? The XP I tried to test on had .Net 3.5 installed. Inputs most welcome.

    Read the article

  • boost thread pool

    - by Dtag
    I need a threadpool for my application, and I'd like to rely on standard (C++11 or boost) stuff as much as possible. I realize there is an unofficial(!) boost thread pool class, which basically solves what I need, however I'd rather avoid it because it is not in the boost library itself -- why is it still not in the core library after so many years? In some posts on this page and elsewhere, people suggested using boost::asio to achieve a threadpool like behavior. At first sight, that looked like what I wanted to do, however I found out that all implementations I have seen have no means to join on the currently active tasks, which makes it useless for my application. To perform a join, they send stop signal to all the threads and subsequently join them. However, that completely nullifies the advantage of threadpools in my use case, because that makes new tasks require the creation of a new thread. What I want to do is: ThreadPool pool(4); for (...) { for (int i=0;i<something;i++) pool.pushTask(...); pool.join(); // do something with the results } Can anyone suggest a solution (except for using the existing unofficial thread pool on sourceforge)? Is there anything in C++11 or core boost that can help me here? Thanks a lot

    Read the article

  • ThreadPool.QueueUserWorkItem new Form CreateHandle Deadlock

    - by bogdanbrudiu
    I have a thread that needs to create a popup Window. I start the thread using ThreadPool.QueueUserWorkItem(new WaitCallback(CreatePopupinThread)) Thew thread creats a new form. The application freases in the new Form constructor at CreateHandle. The Worker Thread is locked... How can I fix this? this is how I create the form var form = new ConfirmationForm { Text = entry.Caption, Label = entry.Text, }; In the constructor the thread enters a deadlock public ConfirmationForm() { InitializeComponent(); }

    Read the article

  • PerThreadLifetimeManager in Unity

    - by DorianGrey
    Hi, In the Unity PerThreadLifetimeManager documentation, I read that: "This lifetime manager does not dispose the instances it holds". Ref.: http://msdn.microsoft.com/en-us/library/ff647854.aspx So, if I am using a ThreadPool, does it mean that objects resolved using Unity on a Thread of the ThreadPool will not get disposed at the end of the work done in that thread before being returned to the pool? Any pattern or ideas how I can ensure that the objects do get disposed & I get a clean thread from the thread pool? Thanks!

    Read the article

  • .NET 1.0 ThreadPool Question

    - by dotnet-practitioner
    I am trying to spawn a thread to take care of DoWork task that should take less than 3 seconds. Inside DoWork its taking 15 seconds. I want to abort DoWork and transfer the control back to main thread. I have copied the code as follows and its not working. Instead of aborting DoWork, it still finishes DoWork and then transfers the control back to main thread. What am I doing wrong? class Class1 { /// <summary> /// The main entry point for the application. /// </summary> /// private static System.Threading.ManualResetEvent[] resetEvents; [STAThread] static void Main(string[] args) { resetEvents = new ManualResetEvent[1]; int i = 0; resetEvents[i] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork),(object)i); Thread.CurrentThread.Name = "main thread"; Console.WriteLine("[{0}] waiting in the main method", Thread.CurrentThread.Name); DateTime start = DateTime.Now; DateTime end ; TimeSpan span = DateTime.Now.Subtract(start); //abort dowork method if it takes more than 3 seconds //and transfer control to the main thread. do { if (span.Seconds < 3) WaitHandle.WaitAll(resetEvents); else resetEvents[0].Set(); end = DateTime.Now; span = end.Subtract(start); }while (span.Seconds < 2); Console.WriteLine(span.Seconds); Console.WriteLine("[{0}] all done in the main method",Thread.CurrentThread.Name); Console.ReadLine(); } static void DoWork(object o) { int index = (int)o; Thread.CurrentThread.Name = "do work thread"; //simulate heavy duty work. Thread.Sleep(15000); //work is done.. resetEvents[index].Set(); Console.WriteLine("[{0}] do work finished",Thread.CurrentThread.Name); } }

    Read the article

  • Java threadpool functionality

    - by cpf
    Hi stackoverflow, I need to make a program with a limited amount of threads (currently using newFixedThreadPool) but I have the problem that all threads get created from start, filling up memory at alarming rate. I wish to prevent this. Threads should only be created shortly before they are executed. e.g.: I call the program and instruct it to use 2 threads in the pool. The program should create & launch the first 2 Threads immediately (obviously), create the next 2 to wait for the previous 2, and at that point wait until one or both of the first 2 ended executing. I thought about extending executor or FixedThreadPool or such. However I have no clue on how to start there and doubt it is the best solution. Easiest would have my main Thread sleeping on intervals, which is not really good either... Thanks in advance!

    Read the article

  • Asynchronous Delegates Vs Thread/ThreadPool?

    - by claws
    Hello, I need to execute 3 parallel tasks and after completion of each task they should call the same function which prints out the results. I don't understand in .net why we have Asychronous calling (delegate.BeginInvoke() & delegate.EndInvoke()) as well as Thread class? I'm little confused which one to use when? Now in this particular case, what should I use Asychronous calling or Thread class? I'm using C#.

    Read the article

  • TimeOuts with HttpWebRequest when running Selenium concurrently in .NET

    - by domsom
    I have a download worker that uses ThreadPool-threads to download files. After enhancing these to apply some Selenium tests to the downloaded files, I am constantly experiencing TimeOut-exceptions with the file downloaders and delays running the Selenium tests. More precisely: When the program starts, the download threads start downloading and a couple of pages are seamlessly processed via Selenium Shortly after, the first download threads start throwing TimeOut exceptions from HttpWebRequest. At the same time, commands stop flowing to Selenium (as observed in the SeleniumRC log), but the thread running Selenium is not getting any exception This situation holds as long as there are entries in the download list: new download threads are being started and terminate after receiving TimeOuts (without trying to lock Selenium) As soon as no more download threads are being started, Selenium starts receiving commands again and the threads waiting for the lock are processed sequentially as designed Now here's the download code: HttpWebRequest request = null; WebResponse response = null; Stream stream = null; StreamReader sr = null; try { request = (HttpWebRequest) WebRequest.Create(uri); request.ServicePoint.ConnectionLimit = MAX_CONNECTIONS_PER_HOST; response = request.GetResponse(); stream = response.GetResponseStream(); // Read the stream... } finally { if (request != null) request.Abort(); if (response != null) response.Close(); if (stream != null) { stream.Close(); stream.Dispose(); } if (sr != null) { sr.Close(); sr.Dispose(); } } And this is how Selenium is used afterwards in the same thread: lock(SeleniumLock) { selenium.Open(url); // Run some Selenium commands, but no selenium.stop() } Where selenium is a static variable that is initialized in the static constructor of the class (via selenium.start()). I assume I am running into the CLR connection limit, so I added these lines during initalization: ThreadPool.GetMaxThreads (out maxWorkerThreads, out maxCompletionPortThreads); HttpUtility.MAX_CONNECTIONS_PER_HOST = maxWorkerThreads; System.Net.ServicePointManager.DefaultConnectionLimit = maxWorkerThreads + 1; The + 1 is for the connection to the SeleniumRC, due to my guess that the Selenium client code also uses HttpWebRequest. It seems like I'm still running into some kind of deadlock - although the threads waiting for the Selenium lock do not hold any resources. Any ideas on how to get this working?

    Read the article

  • Tell Tomcat to drop requests instead of dying "All threads (150) are currently busy"

    - by Nicolas Raoul
    My Tomcat 6.0.26 sometimes dies saying: SEVERE: All threads (150) are currently busy, waiting. Increase maxThreads (150) or check the servlet status ... then Tomcat shuts down, and users can't access the webapp until I restart Tomcat manually. Some of the threads indeed take a long time to execute, it is by-design, not a thread-gone-wild problem. I know I could increase maxThreads, but that is not a viable solution, because the server might receive requests even more requests. QUESTION: Instead of dying, can I tell Tomcat to just drop requests when maxThreads is reached and the AJP/1.3 backlog is full? Below is my server.xml in any case: <?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JasperListener" /> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" minSpareThreads="100"/> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" enableLookups="false" useBodyEncodingForURI="true" backlog="150" maxThreads="150" executor="tomcatThreadPool" keepAliveTimeout="5000" connectionTimeout="300000" /> <Engine name="Catalina" defaultHost="localhost" jvmRoute="ecm1"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> </Host> </Engine> </Service> </Server>

    Read the article

  • C# Multithreading File IO (Reading)

    - by washtik
    We have a situation where our application needs to process a series of files and rather than perform this function synchronously, we would like to employ multi-threading to have the workload split amongst different threads. Each item of work is: 1. Open a file for read only 2. Process the data in the file 3. Write the processed data to a Dictionary We would like to perform each file's work on a new thread? Is this possible and should be we better to use the ThreadPool or spawn new threads keeping in mind that each item of "work" only takes 30ms however its possible that hundreds of files will need to be processed. Any ideas to make this more efficient is appreciated.

    Read the article

  • Java's ThreadPoolExecutor equivalent for C#?

    - by chillitom
    Hi Guys, I used to make good use of Java's ThreadPoolExecutor class and have yet to find a good equivalent in C#. I know of ThreadPool.QueueUserWorkItem which is useful in many cases but no good if you want to control the number of threads assigned to a task or have multiple individual queues for different task types. For example I liked to use a ThreadPoolExecutor with a single thread to guarantee sequential execution of asynchronous calls.. Is there an easy way to do this in C#? Is there a non-static thread pool implementation? Thanks, T.

    Read the article

  • JAVA: 500 Worker Threads, what kind of thread pool?

    - by Submerged
    I am wondering if this is the best way to do this. I have about 500 threads that run indefinitely, but Thread.sleep for a minute when done one cycle of processing. ExecutorService es = Executors.newFixedThreadPool(list.size()+1); for (int i = 0; i < list.size(); i++) { es.execute(coreAppVector.elementAt(i)); //coreAppVector is a vector of extends thread objects } I do need a separate threads for each running task, so changing the architecture isn't an option. I tried making my threadPool size equal to Runtime.getRuntime().availableProcessors() which attempted to run all 500 threads, but only let 8 (4xhyperthreading) of them execute. The other threads wouldn't surrender and let other threads have their turn. I tried putting in a wait() and notify(), but still no luck. If anyone has a simple example or some tips, I would be grateful!

    Read the article

  • Help with porting thread functionality: Win32 --> .Net

    - by JimDaniel
    Hi, I am responsible for porting a class from legacy Win32 code to .Net and I have come across a threading model that I'm not sure how best to implement in .Net. Basically the Win32 has one worker thread, which calls WaitForMultipleObjects() and executes the particular piece of code when a particular object has been triggered. This has a sort of first-come-first-serve effect that I need to emulate in my own code. But I'm not sure how best to do this in .Net. Does anyone have any idea? I see that there is no equivalent of WaitForMultipleObjects() in .Net, only the ThreadPool class, which seems to provide most of what I need, but I'm not sure if it's the best, since I only have four objects total to wait and execute code for. Thanks, Daniel

    Read the article

  • Running a ProgressDialog MonoAndroid

    - by user1791926
    I am trying to run a progressDialog that will loading items into a Sqlite datebase on a first load for my application. I get an error message because the application runs the rest of the code in the application before the rest of the data is loaded into the database. How do I make sure the code is completed in the progressDialog before the code in the rest of the program? LocalDatabase DB = new LocalDatabase(); var dbpd = ProgressDialog.Show(this, "Loading Database", "Please wait Loading Data",true); ThreadPool.QueueUserWorkItem((s) =>{ DB.createDB(); RunOnUiThread(() => databaseLoaded()); });

    Read the article

  • 500 Worker Threads, what kind of thread pool?

    - by Submerged
    I am wondering if this is the best way to do this. I have about 500 threads that run indefinitely, but Thread.sleep for a minute when done one cycle of processing. ExecutorService es = Executors.newFixedThreadPool(list.size()+1); for (int i = 0; i < list.size(); i++) { es.execute(coreAppVector.elementAt(i)); //coreAppVector is a vector of extends thread objects } The code that is executing is really simple and basically just this class aThread extends Thread { public void run(){ while(true){ Thread.sleep(ONE_MINUTE); //Lots of computation every minute } } } I do need a separate threads for each running task, so changing the architecture isn't an option. I tried making my threadPool size equal to Runtime.getRuntime().availableProcessors() which attempted to run all 500 threads, but only let 8 (4xhyperthreading) of them execute. The other threads wouldn't surrender and let other threads have their turn. I tried putting in a wait() and notify(), but still no luck. If anyone has a simple example or some tips, I would be grateful! Well, the design is arguably flawed. The threads implement Genetic-Programming or GP, a type of learning algorithm. Each thread analyzes advanced trends makes predictions. If the thread ever completes, the learning is lost. That said, I was hoping that sleep() would allow me to share some of the resources while one thread isn't "learning"

    Read the article

  • Recursively adding threads to a Java thread pool

    - by Leith
    I am working on a tutorial for my Java concurrency course. The objective is to use thread pools to compute prime numbers in parallel. The design is based on the Sieve of Eratosthenes. It has an array of n bools, where n is the largest integer you are checking, and each element in the array represents one integer. True is prime, false is non prime, and the array is initially all true. A thread pool is used with a fixed number of threads (we are supposed to experiment with the number of threads in the pool and observe the performance). A thread is given a integer multiple to process. The thread then finds the first true element in the array that is not a multiple of thread's integer. The thread then creates a new thread on the thread pool which is given the found number. After a new thread is formed, the existing thread then continues to set all multiples of it's integer in the array to false. The main program thread starts the first thread with the integer '2', and then waits for all spawned threads to finish. It then spits out the prime numbers and the time taken to compute. The issue I have is that the more threads there are in the thread pool, the slower it takes with 1 thread being the fastest. It should be getting faster not slower! All the stuff on the internet about Java thread pools create n worker threads the main thread then wait for all threads to finish. The method I use is recursive as a worker can spawn more worker threads. I would like to know what is going wrong, and if Java thread pools can be used recursively.

    Read the article

  • Help regarding C# thread pool

    - by Matt
    I have a method that gets called quite often, with text coming in as a parameter.. I'm looking at creating a thread pool that checks the line of text, and performs actions based on that.. Can someone help me out with the basics behind creating the thread pool and firing off new threads please? This is so damn confusing..

    Read the article

  • Advantages of Thread pooling in embedded systems

    - by Microkernel
    I am looking at the advantages of threadpooling design pattern in Embedded systems. I have listed few advantages, please go through them, comment and please suggest any other possible advantages that I am missing. Scalability in systems like ucos-2 where there is limit on number of threads. Increasing capability of any task when necessary like Garbage collection (say in normal systems if garbage collection is running under one task, its not possible to speed it up, but in threadpooling we can easily speed it up). Can set limit on the max system load. Please suggest if I am missing anything.

    Read the article

  • How to manage the default Java SwingWorker thread pool?

    - by Guy Lancaster
    I've got an application that uses 2 long-running SwingWorker tasks and I've just encountered a couple of Windows computers with updated JVMs that only start one of the them. There are no errors indicated so I have to assume that the default thread pool has only a single thread and therefore the second SwingWorker object is getting queued when I try to execute it. So, (1) how do I check check how many threads are available in the default SwingWorker thread pool, and (2) how do I add threads if I'm going to need more? Anything else that I should know? This apparent single-thread thread-pool situation goes against all of my expectations. I'm setting up a ThreadPoolExecutor but this seems so wrong...

    Read the article

  • Terminate long running thread in thread pool that was created using QueueUserWorkItem(win 32/nt5).

    - by Jake
    I am programming in a win32 nt5 environment. I have a function that is going to be called many times. Each call is atomic. I would like to use QueueUserWorkItem to take advantage of multicore processors. The problem I am having is I only want to give the function 3 seconds to complete. If it has not completed in 3 seconds I want to terminate the thread. Currently I am doing something like this: HANDLE newThreadFuncCall= CreateThread(NULL,0,funcCall,&func_params,0,NULL); DWORD result = WaitForSingleObject(newThreadFuncCall, 3000); if(result == WAIT_TIMEOUT) { TerminateThread(newThreadFuncCall,WAIT_TIMEOUT); } I just spawn a single thread and wait for 3 seconds or it to complete. Is there anyway to do something similar to but using QueueUserWorkItem to queue up the work? Thanks!

    Read the article

  • Threads in WCF service

    - by dragonfly
    Hi, there is a piece of code: class WCFConsoleHostApp : IBank { private static int _instanceCounter; public WCFConsoleHostApp () { Interlocked.Increment(ref _instanceCounter); Console.WriteLine(string.Format("{0:T} Instance nr " + _instanceCounter + " created", DateTime.Now)); } private static int amount; static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof(WCFConsoleHostApp)); host.Open(); Console.WriteLine("Host is running..."); Console.ReadLine(); } #region IBank Members BankOperationResult IBank.Put(int amount) { Console.WriteLine(string.Format("{0:00} {1}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread) + " Putting..."); WCFConsoleHostApp.amount += amount; Thread.Sleep(20000); Console.WriteLine(string.Format("{0:00} {1}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread) + " Putting done"); return new BankOperationResult { CurrentAmount = WCFConsoleHostApp.amount, Success = true }; } BankOperationResult IBank.Withdraw(int amount) { Console.WriteLine(string.Format("{0:00} {1}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread) + " Withdrawing..."); WCFConsoleHostApp.amount -= amount; Thread.Sleep(20000); Console.WriteLine(string.Format("{0:00} {1}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread) + " Withdrawing done"); return new BankOperationResult { CurrentAmount = WCFConsoleHostApp.amount, Success = true }; } #endregion } My test client application calls that service in 50 threads (service is PerCall). What I found very disturbing is when I added Thread.Sleep(20000) WCF creates one service instance per second using different thread from pool. When I remove Thread.Sleep(20000) 50 instances are instanciated straight away, and about 2-4 threads are used to do it - which in fact I consider normal. Could somebody explain why when Thread.Sleep causes those funny delays in creating instances?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >