Difference Between ThreadPool And BackgroundWorkers?

Jan 11, 2009

I'm currently writing an application that is used to automate a certain task. Currently, it uses the threadpool (using up to 25 threads per the enduser's option). Each thread calls a function which will usually take about two minutes to finish, but it uses a While loop in order to repeat the process. This is my code to start the threads:

Private Sub ProcessAllItems()
For i As Integer = 1 To Me.numThreads.Value Step 1
Threading.ThreadPool.QueueUserWorkItem(New Threading.WaitCallback(AddressOf ProcessItem), i)
Next i
End Sub

The function "ProcessItem()" is the function that contains the While loop. The control "Me.numThreads" is a NumericUpDown control whose max value is set to 25. My question is...is this a good method to follow? To my knowledge after .NET Framework SP1 there is a max of 250 threads/CPU. However I've read the the threadpool is normally used for processing short-lived tasks. Should I be using background workers instead? If so, how could I start up to 25 background workers during runtime depending on the value of "Me.numThreads"?

View 14 Replies


ADVERTISEMENT

VS 2008 2 Threadpool - One Threadpool For Scanning Files And Second Threadpool For Moving File's Into Drive's

Jun 4, 2011

I m trying to move all my drive's files into h drive firstly i have added all drives in threadpool for scanning and when scanning of any drive finish (Without waiting for other drive's complete ) it will move file's to h drive but it is not working as i wanted that's why i need two threadpool - one threadpool for scanning files and second threadpool for moving file's into drive's

View 11 Replies

Running Multiple BackGroundWorkers?

Jun 6, 2011

I am writing an automation program that runs 4 test boxes in line with a handler. Im having a problem with running 4 BGWs(back ground workers). The Program is running fine right now but its not running the way it was designed. What i am trying to do is get all 4 BGWs to run in parallel. what its doing right now is running 3 and then when those three are done running it runs the 4th. the crazy part is its not running 1 2 3 then 4 its running 1 2 4 and then 3. Also its not updating my status windows right either.

[Code]...

View 1 Replies

How To Test If Multiple Backgroundworkers Have Completed

Mar 15, 2011

I'm trying to develop an application which searches a sql server database. One particular search entered by the user actually sends seven queries to the database. I've designed it so each of the seven queries is conducted in a seperate backgroundworker, so that they run and return their hits concurrently. When the user enters a search term, a routine (runSearch) is called , which in turn causes each seperate backgroundworker to run.This work fine when the user enters a single search term.I'm now trying to allow the user to enter multiple search terms in a multiline textbox. I iterate through the lines in the textbox and call runsearch for each line. I assumed that the progam would wait for each call to runsearch to complete, before running the next.

I now find out this is not the case. When I call runSearch, the backgroundworkers are set in motion. The next line in the textbox then calls runSearch again, but the backgroundworkers from the previous calling of runSearch are still running. This throws up an error stating that the backgroundworker is still busy and cannot be called.I need a way to test that all of the backgroundworkers have completed before running runsearch again. If one or more of the backgroundworkers are still running

View 19 Replies

VS 2008 Implement Multiple BackGroundWorkers?

Mar 24, 2009

I am making an application that has a tabbed interface. Each tab uses a UserControl with the controls that I need on it. The user enters some data & clicks a button, which starts a lengthy process. I would like to run that process in a BGW, so that the user can switch to (or open) another tab & process another set of data simultaneously.

View 7 Replies

Single Task Processed By Multiple Backgroundworkers?

Jun 23, 2010

I have an array that is a list of files in a folder, I'm processing the files and renaming them. It takes about 15 minutes to rename them all, this is done daily. I currently have 1 Backgroundworker to handle this and update the UI.

My question is, this: How can I use more than 1 Backgroundworker to use more than 25% of the CPU to do this?

Split the array into 3 parts and call 3 separate workers to do their part?

View 3 Replies

VS 2008 BackgroundWorkers - Does Not List Files In Order

Nov 26, 2010

The code uses dynamically backgroundworkers which all workers great, but with one problem. If you were to look at line:
For Each folderPath In File.ReadAllLines("file path here")
You would see that it loops the text file, and starts background work.
The problem is that it does not list the files in order.
For example were you see "file path here" that were you put the file path.
The text file itself would look something like this:
C: est
C:VB
The program starts listing file from the C:est then goes back to C:VB then back to C:est.

I know the reason why, but I can't stop it. I tried pausing that code inside the loop, but with no luck. How would be able to list the files in order?
vb.net
Private filePaths As New List(Of String)
Private workers As New List(Of BackgroundWorker)
Private Sub GetAllFiles()
For Each folderPath In File.ReadAllLines("file path here")
Dim worker As New BackgroundWorker
[Code] .....

View 8 Replies

Backgroundworkers Do Not Properly Check The Images Against The Ones Stored In Program?

Aug 22, 2010

I am making a program that takes pictures of the webbrowser control on a set timer and save them in a picturebox.. I then use backgroundworkers to check the images against others stored in the program. My issue is, the backgroundworkers do not properly check the images against the ones I have stored in the program.Could this be because the images and picturebox are stored on the main thread, and no in a background worker?In other words, I am taking picture from my webbrowser and putting them in my picturebox. Then, I am comparing them with images already in the images. The only problem is, the workers are unable to properly compare the images.

View 6 Replies

ThreadPool And Delegate In C# To .NET?

Jan 1, 2010

how this is written in VB.NET? This was an example I found on [URL]

ThreadPool.QueueUserWorkItem(delegate
{
var channelFactory = new ChannelFactory<ISimpleService>("*");
var simpleService = channelFactory.CreateChannel();
var asyncResult = simpleService.BeginGetGreeting("Daniel", null, null);

[code]....

View 3 Replies

.net - Threadpool Using Upto 200 Threads?

Jun 26, 2011

i have this code which i run with queued 10,000, even when a max of 50 is set but the threadpool counts goes to high.

Public Sub DoWork(ByVal objItem As Object)
Dim objUrl as String = DirectCast(objItem, string)
Try
If objUrl Is Nothing Then

[code]....

EDIT:i use a this code to check the number of runing threads each second

Sub Timer1Tick(sender As Object, e As EventArgs)
tsslthreads.Text=string.Format ("Threads: {0}", Process.GetCurrentProcess().Threads.Count)
End Sub

View 3 Replies

Async Callback From ThreadPool?

Jun 12, 2009

I have a bunch of operations that need to be executed simultaneously. For this I'm using the thread pool to execute the tasks. I'd like to know if it's possible to consume some sort of Async Callback (similar to BackgroundWorker.DoWorkComplete) when each thread is finished. The reasoning behind this is that I have a windows service running that uses IPC to update a GUI and I need to know the time at which each specific thread finishes I've used background workers to do a set of tasks and they work perfectly, however, they take longer than I would like. I've timed the execution on my BGW method for a designated number of said tasks and it took 27 seconds, and the same set of tasks takes 4 seconds using the threadpool method. I've also tried using managed threads, to the same effect as the background workers.

View 5 Replies

Forms :: Threadpool With Progress Bar?

Jul 2, 2009

currently i am using a threadpool that contain a number of thread. This number of thread can be different everytime, sometimes 5, sometimes 10, sometimes 15 and so on (multiple of 5). So now i have it working good by using for loop to queue the thread into threadpool. Now the problems is i do not know how to make the progress bar depending on my threadpool. I want my progress bar to complete only when all the thread are done. After searching google, i found that maybe it can be solve by using AutoResetEvent(false), but after i apply to my program, it still did not work, my program hang at xEvent.WaitOne() method and didnt proceed further, anyone can explain to me how to solve the problem? Or got any other ways? For your information, only 5 threads can be running at the same time as the requirement state so (so i set the setmaxthread to 5 already).

View 1 Replies

Not Enough Free Threads In ThreadPool

Mar 15, 2011

anybody familiar with these error? "There were not enough free threads in the ThreadPool object to complete the operation".im calling a web service in my windows application client.

View 16 Replies

Threadpool And Threading In General?

Jun 5, 2010

whipped up this code real quick which uses a ThreadPool on Form Load to iterate through my subnet and tell me if there's a device communicating at each IP address.

some questions: Why am I able to update BOTH my label at the top AND the listbox, but I'm only using an .Invoke on the Listbox?How can I know how many threads are currently being used while that is executing?

What does the SyncLock do?I'm aware some people don't like the use of Application.DoEvents(). Is it ok to be using it in this instance or is there a better practice?For those wanting to try it out, drag a Label and a Listbox to a new form. Label is called "currentIPTextbox", Listbox is default name.

[Code]...

View 14 Replies

ThreadPool Not Working In Parallel

Feb 12, 2010

I prepare data to be processed, and saved to file. Since this process is slow, I want to delegate it to a parallel thread, so the main routine can end his work faster. The data is processed and saved to file by the "Sub ProcesarDatos", a routine on his instance of "FileProcessor class".

I call the code this way:
Dim
fp As
New
FileProcessor(DatosDeArchivo, Archivo & ".txt", Me)
ThreadPool.QueueUserWorkItem
(NewSystem.Threading.WaitCallback _
AddressOffp.ProcesarDatos))

View 2 Replies

ThreadPool.QueueUserWorkItem Sometimes Slow?

Feb 14, 2012

I am using VB.NET 2008.Every now and then, ThreadPool.QueueUserWorkItem can take up to 500 msI checked the available thread, and it's not 0.What can cause ThreadPool.QueueUserWorkItem to take long sometimes, and how can I make it faster ?

Do While Not TerminateRisk
While qRiskSync.Count > 0
sItem = qRiskSync.Dequeue

[code]....

View 1 Replies

VS 2008 - Threadpool Example For Scraper

Mar 9, 2012

can somebody give ThreadPool example for application thats needs to get information to datagridview from thousands of sources? My application needs to work fast and without freezing and lag, but I cant figure out this threadpool thing. And would be nice if you could add this thing to example that when I set domainupdown value to 25 as example, it sets threads to 25. So its making work 25x faster. I haven't find any good example for this, only some C# examples but they haven't work after i converted those to vb.net.

View 1 Replies

VS 2008 How To Stop Threadpool

Nov 20, 2009

I have a app that gathers and store updated data from a list of websites. My app use threadpool and each thread visits a site within the list and gathers the data. I want to create a stop button to stop/ prevent threadpool from running once it is clicked. How do I go about doing this?

View 1 Replies

VS 2008 Threadpool With Progress Bar?

Jul 1, 2009

currently i am using a threadpool that contain a number of thread. This number of thread can be different everytime, sometimes 5, sometimes 10, sometimes 15 and so on (multiple of 5). So now i have it working good by using for loop to queue the thread into threadpool. Now the problems is i do not know how to make the progress bar depending on my threadpool. I want my progress bar to complete only when all the thread are done. After searching google, i found that maybe it can be solve by using AutoResetEvent(false), but after i apply to my program, it still did not work, my program hang at xEvent.WaitOne() method and didnt proceed further, anyone can explain to me how to solve the problem? Or got any other ways? For your information, only 5 threads can be running at the same time as the requirement state so (so i set the setmaxthread to 5 already).

View 2 Replies

Forms :: Opening Form Using A Threadpool?

Sep 15, 2009

I want to open a VB.net form using a ThreadPool with a maximum of 10 threads. I need to do this because, the form should open based on a live event and i need atmost 10 forms on the desktop at a time. If i open the form on every live event without using a ThreadPool, the desktop will be floaded with many forms. I am using QueueUserWorkItem method of threadpool to queue a method which opens the form. In this queued method, there is form1.show() statement called. But after displaying the form, this method finishes execution and again we have 10 threads available in the system. I somehow want to either keep this method running so that 1 thread is occupied or i want to keep the thread alive till the form1 is closed by the user. I want the 11th form to appear on the desktop, only when any of the existing forms out of the 10 (already on desktop) is closed.

View 2 Replies

Keep Object Alive For Threadpool / Timercallback?

Jun 4, 2009

When using teh system.threading.timer or threading.threadpool. queueuserworkitem, you are able to pass an object.

But wouldn't the garbage collector destroy the object even before the callback can be executed?[code]...

View 2 Replies

ThreadPool And Large Processing Of WorkItem?

Oct 11, 2010

Been trying to implementing ThreadPool over a large and variable amount of data like the following:

public sub ProcessWorkItem(byval state as object)
Dim originalState as CustomStateInfo = CType(state, CustomStateInfo)
'Do stuff

[Code]....

This of course will bomb out if we have more than 64 items/threads being placed on the ThreadPool.

So, how would one process say x amount of items until there are no more items left to process?

View 30 Replies

Use ThreadPool Without Making Sub Foo(o As Object) Each Time?

Feb 7, 2010

Every time that I want to make a thread in the ThreadPool I make a stupid little function like Worker_O below.[code]...

Is there a way in VB .net to cast from Sub(i as integer) to Sub(o as object) without making Worker_O? Worker_O is ugly to me.

View 1 Replies

Canceling A ThreadPool Thread That's Being Blocked By A .NET Method?

Aug 14, 2009

I have a task that needs to be executed many times in a thread, so as to keep my GUI responsive. Right now I'm using the ThreadPool to accomplish the tasks, and it works perfectly. I get all the data I expect back from the threads, life's good. When those tasks are finished, I then fire off another set of threads to accomplish another set of tasks, in the same fashion. The work method of these threads uses a call to RegistryKey.OpenRemoteBaseKey, which does exactly that, opens a remote registry key. The problem is: if the user running the application does not have permission to open the remote registry the call will throw an IOException, but I expect this behaviour because the user does not have permission to do it. However, the call itself can take FOREVER.

I wrote the application initially to use delegate methods and used the WaitHandle.WaitOne() method on AutoResetEvents in a state object I passed to each delegate. I tried the WaitOne method using a timeout, which worked fine until I realized that even though the WaitOne timed out, the thread was still running. This is a problem because (from what I understand) processes are only given a certain number of ThreadPool threads and, once used, they must be finished in order to be released back to the threadpool. In my work method, I also have a variable that can be signalled when the thread should be stopped, but that (obviously) only works on code that I've written.how can I cancel a thread that's stuck on a .NET method? Is there some sort of garbage collection method I can call if I give it a handle?

View 18 Replies

Incompatible Signatures When Spawning Thread With ThreadPool?

May 5, 2009

The error is:

Method 'Private Sub ProcessToolWork()'
does not have a signature compatible
with delegate 'Delegate Sub

[code].....

View 2 Replies

Make Threadsqueued To Threadpool Execute Sequentially?

Sep 13, 2011

Learning about threads at the moment, barely managing to wrap my head around it, anyway I was wondering how you would go about making threads run sequentially from threadpool if you added them with
threadpool.queueuserworkitem()

In my code currently I know it is not running sequentially as I set it up to call a function and print a number each call. I gather this could be achieved with using synch lock but not quite sure how.

View 5 Replies

Threadpool Threads Detect Finished Processing

Jun 28, 2011

what is the best way of detecting if all the threads in the threadpool have finished working,

is there anyway to stop all the threads?

[URL]

View 8 Replies

VS 2008 Threadpool - Web Scrapper Which Loops User Set List Of URL

Feb 29, 2012

I am doing one web scraper which loops user set list of urls. Lists can be huge and that's why I need Threadpool for it.

My code so far (Scrape code missing)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ThreadingEvents(20) As ManualResetEvent
Dim iCounter As Integer = 0
For Each item As Object In ListBox1.Items
[Code] .....

View 4 Replies

VS 2010 Looping And Freezing - Add All The Users To A Threadpool To Do A Certain Function?

Jan 16, 2012

I have a code which adds each line of a textfile to a List(Of String).I have around 1.5 million entries in the textfile. It adds it to the list in like 1 second. However, I'm trying to add all the users to a threadpool to do a certain function. So I try:

For i as integer = 0 to list.count - 1

The list has like 1.5 million entries so the GUI freezes untill it all finishes in like 5 minutes. How can I make it go faster and not freeze the GUI?

View 6 Replies

Stop A Threadpool When User Press Cancel Task Button?

Jul 20, 2011

Is there any direct way to stop a threadpool when user press Cancel Task button? I got SmartThreadPool but using that i could not arrange my code. Its becoming difficult.

Here is my simple code:

'Delegaet to update UI
Public Delegate Sub updateClassDelegate(ByVal index As Integer, ByVal status As String)

[Code].....

View 9 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved