VS 2005 Pause A Thread - Let Other Threads Run

Dec 5, 2010

In my application I have a loop that makes calls to a website to download data. I'm using a DownloadDataAsynch call with a handler.

I'm making many such calls in a loop. What I'd like to do is, if I have more than a certain number of replies pending, I should pause the loop and let the data handlers run.

How do I do that?

CODE:

View 14 Replies


ADVERTISEMENT

Waiting For Threads - Thread.join Suspend Execution Of Code On Calling Thread Until Spawned Thread Finishes Or Is Aborted

Sep 2, 2010

My understanding is that thread.join will suspend the execution of code on the calling thread until the spawned thread finishes or is aborted...

With that in mind, I tried this:

For i = 1 to 50
threads = New Thread(AddressOf test)
threads.IsBackground = True
threads.SetApartmentState(ApartmentState.STA)

[CODE]...

However, the rest of the code runs when the loop finishes, not waiting for all the spawned threads to finish. Since the rest of the code needs the threads to finish (otherwise the rest will error).

View 4 Replies

Pause Threads Or Recreate?

Feb 20, 2009

I've created a class that manages two threads for reading from the stdout and stderr streams of a child process. The class is working fine now by pausing the threads when they aren't needed by calling Thread.Sleep(Timeout.Infinite), but I have a question about resource usage...

Does it make more sense to allow the threads to finish execution and recreate them when needed or to just sleep them and then wake the threads up via Thread.Interrupt when needed?

View 1 Replies

VS 2008 - Pause Thread For Half A Second?

Jan 6, 2010

How can I do a function, pause my thread for half a second or 1 second then do another function like for a random example.
Timer1.Start
'Pause for half a second
Timer2.Start

View 2 Replies

VS 2008 Proper Way To Pause/resume A Thread?

Oct 6, 2011

I have a thread running on my application that checks a database every so often to decide whether or not to update nodes in a treeview.

Each treeview node represents a document and I have an open button that opens the document for the user.

When the document is opened, I wanted to suspend the thread that refreshes the node list until the document is closed.

I have MyThread.Suspend and MyThread.Resume. But the document viewer is on another thread.

I created functions for suspending/resuming the thread in the application. I have delegates in the viewer to call those functions from another thread. But I'm still getting an Error. "Thread is not user-suspended. Cannot be resumed" or something of the like.

But I realize that Suspend and resume are obsolete functions, so what class or objects should I be looking into and if it didn't take up too much of your time, a small example as well?

View 6 Replies

VS 2010 Pause Line Of Code Without Using Thread?

Jun 3, 2010

Okay so I have a webbrowser that navigates to 1 page and I want it to wait 5 seconds and go to the next page, then I want it to wait 5 seconds and go to the next page I want it to navigate to and so on... I tried thread.sleep but I don't want to have the form stop completely in case someone wants to minimize the form. I thought about using a timer to tell it how long it wants to stop and go.

View 4 Replies

Running All Threads Not On The GUI Thread?

Dec 7, 2011

I have only managed to use an STA to run a long running excel process with a background worker and 2 delegates.

What I want to do now is have the whole application running outside of the main thread to make sure the UI is always available, I then want to create new threads from the thread I have outside of the main to run the various processes. I will need to have some form of syncronisation in there for certain things to be done once a thread is completed and also I will need to change the button states on the main form to stop certain process being called whilst other processes are running.

This is my code so far, basically this loads in a csv file to a datatable adding manager employee ID and email address, filters it and displays the resultant data in a listview. There eventually will be some filter options as well. There are then 2 options for processing the data, it will produce individual bradford factor reports and email them to each manager or will produce a summary spreadsheet that is sent to HR.

Currently because there are around 8000 lines of data, it was the summary option that required the background worker as a long running process time out error was occuring whilst in the main.

What it does is write the data from the list view to an excel sheet and colour co-ordinates the summary rows according to the absense policy. It then copied bottom to top, the summary value the next blank column against all the lines for that individual and then uses this column to decide which sheet to move the row to, copying the row to the new sheet then deleting it from the master list and shifting the cells up.


This works well, but the process of loading the data in to the list view locks up the main thread where it currently runs. I also wanted to make this slightly more complicate as far as threading is concerned, as more of a learning curve than a practical application of the function.

Here is my code so far: [URL]

View 10 Replies

Run A Thread And Then At A Certain Point pause It And Wait For The User To Enter Some text?

Sep 20, 2010

I want to be able to run a thread and then at a certain point pause it and wait for the user to enter some text into a text box and then when they press submit i want the program to run again from where it left off.

View 10 Replies

Finding 1 Thread Out Of The 3500+ Threads?

Jan 3, 2010

Trouble finding 1 thread out of the 3568 threads I have in my history.In the one I'm looking for I wrote an Extension Method called Shape , I think.

The code could change the Shape of any Control and I think I added similar code for any FORM in the same thread but not for User Controls.

Does anyone remember roughly what year and month it was?

It might save me hunting through my past threads.

[Code]...

View 4 Replies

What Is The Max Number Of Threads In The Thread Pool

Sep 22, 2009

I've been reading up on multi-threading and just have a couple trivia questions that are ambiguous given my sources:

1) What is the max number of threads in the thread pool? The number 25 is used but I have on reference that says 25 per CPU and another that says 25 per core. I realize that both can be right but before I start making flagrant design decisions I'd like some validation.

2) Let's say I'm in the body of a delegate and I call a function or sub. Does that function/sub remain in the thread or does it revert to the parent thread? I'm guessing the former would be much easier to implement so that's probably what MS did but you just can never tell.

View 10 Replies

1 To N Thread - Show A Definite Number Of Threads?

Sep 3, 2009

Does anyone have a 1 to n thread example in which n threads are created dynamically? There are a number of examples that show a definite number of threads, and some that imply n threads by using a tcp ip listener or a file system listener. However, I'm looking for a 1 to n created in response to a dynamic requirements, provided purely by and for my program.Essentially, my requirement is to be scalable. 1 to n threads based on application throughput should make this pretty easy to satisfy.

View 9 Replies

Running Threads In Thread.Pool Sequential?

May 19, 2012

I have several threads in my WinForm and I am running them via Thread.Pool, what I need to know is that how can I run them sequentially.

example:

Thread1 => me.label1.text = "Thread1"
Thread2 => me.label2.text = "Thread2"
Thread3 => me.label3.text = "Thread3"

In my Form_Load event, I have a line as follows:

[Code]...

View 8 Replies

Stop All Threads Or Just The Thread That The Statement Is Executed In?

Dec 12, 2010

I'm working with vb.net 3.5SP1 /VS2008. I'm familiar with windows threads from C++ but I didn't do it since the 90s.I have 5 threadpool calls (ThreadPool.QueueUserWorkItem) that do some complex work (they read info from different web pages, regular expressions, etc) and each updates different columns in a data-grid view. They pause for 1 second between each web read with thread.sleep (not to overload the server). My issue is that some of the threads do not complete. I get for example 3 results when I should have 8. Sometimes it works fine. This is an older 3.0Ghz HT machine, I want to test it on the lowest common denominator(and that is all I have ). I tried using Monitor.Enter(ListView1)it seems to help but it is hard to tell. I tried using the thread debug window but it is not really helpful, it seems do disappear during execution. If I remove the threads I always get my data. I'm wondering if something is being blocked? Is there a way to debug this?

Also, does thread.sleep(x) stop all threads or just the thread that the statement is executed in?

View 4 Replies

Trap Exceptions In Thread Pool Threads?

Jun 15, 2012

I have a thread pool that send file using ftp protocol. I encapsulated the call for threadpoll with try catch believing that the thrown exception inside the threadpool will be catch by the main thread. Instead the system terminate whenever i throw an exception from inside the threadpool. Also I design the Clsftp.ftpsend class to throw an exception related to ftp error. Basically my design for handling the error is just like the code below.

'Main thread
Private Sub BttnStartSending_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BttnStartSending.Click
try
Dim objparam As New ThreadParameter

[code]....

View 7 Replies

Enumerating Managed Threads Or Determining When A Thread Is Created?

Feb 15, 2010

I have need of either enumerating all the managed threads in a application or listen to when a new thread is created. I can not find anyway to do this through searching the web. It strikes me as odd the the IDE can list all the manage threads, but I can't.

If this is not possible, is there clarification as to why this is not possible.

I need to create a shared class in a DLL that will when it receives a signal will stop all the threads currently running, and gracefully exit the application.

View 3 Replies

Pass Objects Between Threads Before Child Thread Completes

Oct 15, 2009

What is the best way to pass objects between threads? I would like to create a new thread that creates a new object : Dim myobject as newobject = new newoject Then in my main thread, I would like to use myobject. Ideally I would like to just assign to a global variable but I don't think that is possible. I think I may have to use some form of delegate function (but I think the child thread would need to complete to use a callback). The new thread will not actually end before I need the object reference in the main thread. How should I go about this?

View 2 Replies

C# - Does Queuing Threads Impact Non-thread Safe Objects In The Same Class

May 23, 2011

c# - Does queuing threads impact non-thread safe objects in the same class?

View 1 Replies

Does Queuing Threads Impact Non-thread Safe Objects In Same Class

May 7, 2009

If I spawn a thread with ThreadPool.QueueUserWorkItem and that thread does not reference the object that is not thread safe, would it compromise that non-thread safe object? By not thread safe object, I mean a third party interface to a programmable logic controller that has no ability to open simultaneous connections or concurrency support.I suppose I just wanted to be sure that by queuing threads in the same class as my reference to that object, I wouldn't somehow be compromising its thread safeness in a way I didn't realize.

View 2 Replies

Thread About Threads - Made A Rapid File Transfer Form For Photos?

Apr 29, 2010

I just made a rapid file transfer form for my photos.In which I drag photos into a listview with my destination folder set.I assign each individual file transfer to a new thread. This works very fast as compared to the standard drag n' drop.

View 2 Replies

VS 2010 - Using System.Threading.Thread.Sleep(5000) To Let My App Pause/sleep For Some Time

May 25, 2010

Currently I'm using System.Threading.Thread.Sleep(5000) to let my app pause/sleep for some time. This works great but I can't open my app anymore when it's sleeping and it uses about 25% of my CPU. I guess there must be a better way to do this. I also tried using a timer but that didn't work out to well for me..

View 5 Replies

Is Running Multiple Threads Faster Then A Single Thread On A Single Core Cpu

Dec 23, 2009

Say I have a code with 3 methods that do some pretty intensive work. Would executing these methods on 3 seperate threads be faster then executing them one after the other on a single core cpu? And what if it's a dual core or HT?

View 8 Replies

Why The Pause Button And Also The Pause Command Does Not Exist In VB 2010 Express

Mar 8, 2010

1) Why the pause button and also the pause command does not exist in VB 2010 Express?

2) I have some solutions under 2010. In 2 or 3, while debugging, I can change instructions without restarting the application. In others, I cannot change anything (Is like readonly), Looking in 'My Applications', Tab 'Debug', Option 'Configuration' I can choose several Options. In the applications I can debug, the default is 'Active (Debug)'; in the others is 'Active (Release)'. If I change the options, the word 'Active' remains attached to the original option.

View 5 Replies

VS 2005 - Multithreading - How Are Threads Accessing The Sub

Oct 15, 2010

I have 10 threads each using the same sub to do work. This sub is calling a function to save the results. How are the threads accessing the sub? Is each one getting a fresh copy of the sub to do its thing or are they using the same piece of code and need to wait for each other to finish processing? I don't get any hits when searching for such a specific scenario. I am wondering because it is about using sockets (usually lightweight stuff) to retrieve a resource and the cpu is working at 100% all the time. Still it is very fast, 900 internet queries finish in about 3 minutes.

View 4 Replies

VS 2005 Converting Class To Use Threads?

Mar 29, 2010

I have a class that includes a timer :-

public class clsQueryObject
private tmrPoll as new timer
Public sub New()

[code]....

View 3 Replies

Communications :: Involving Cross Threads In .NET 2005?

Feb 8, 2010

My application need to communicate with my self made device through serial port. I have to change the selected index of Tabs when I press a button on my device. I have Form1, Form2, Module1 Form1 Contains the Serial Port Control. Form2 contains the Tab which needs to be changed. When I press a button on device them, the button pressed is stored in an integer form in a global variable.The Interrupt for the Serial Port directs the control to the module1 where I decide using Select Case that what index of which TabControl I have to select.Depending on that, I change the Index of the required Tab.

PROBLEM:cross thread exception is fired as soon as the control reaches the statement where I Modify the SelectIndex property from the select case at Module1.While, on my other PC, the SelectIndex property is changed, but the next tab is not shown.

BUT, if I put all this code in a button control, and try to activate from there, then it works perfectly. However, I have to navigate through the tab controls using my self made device.I searched a lot on net and came across a solution which describes that we have to use delegate function and invokeRequired methods to ensure that the procedures run on the same thread.I am not able to decide that where exactly shoud the code for delegates and all be written, in form1, or form2, or module1.Also, in the hit and try that I did, I always got the value of InvoleRequired as False.

Here is the part of Code that I wrote for Delegates

Code:

'Form 1 is BLINDHELPER_SIGNIN
'form 2 is BLINDHELPER_USER

' I have defined these at Module1

Public Delegate Sub DeleToManageTabs(ByVal tb As TabControl)
Public Sub manage_Tabs(ByVal tab As TabControl)
MsgBox(tab.Name)

[code]....

After using this code also, there is no change in working of my application.

View 3 Replies

[2005] Display A Randomly Generated Sentence On The Screen Wait - Pause - Timeout - Standby?

Jan 26, 2009

My program is supposed to display a randomly generated sentence on the screen (something like a screensaver) Then 'wait' for a random period between 1 and 5 minutes before cycling through to generate another sentence. How do I do that?

[Code]...

View 5 Replies

Multithreading - .NET 4.0 Execute Multiple Threads But Threads Are Completed Before Resuming?

Oct 19, 2011

I just had a new, last-minute idea on to take on a task, so I am running to StackExchange for quick help.

What I want to do is execute a series of methods right in a row, each in their own threads. I want the application to wait until all of these threads are completed, after which the program will resume. It also has to use managed threading (thread pool).

What quick examples could you provide to help me along the way? If it's too complex, what things should I know about so that I can Google it on my own?

View 1 Replies

Queue Threads - Spawn A Series Of 'child' Threads From A Loop

Dec 30, 2009

I have a main thread which is designed to be a batch processor - it spawns a series of 'child' threads from a loop (which can vary in terms of the no of items) - see below

[Code]...

However, each of the 'child' threads could take anywhere from milliseconds to about a minute to process - depending on the complexity of each calculation. There may also be a large number of child threads - e.g 100s. Creating large numbers of child threads is not efficient. I therefore want some way to effectively queue each child thread (and cancel if the process is taking too long to complete). Autoevents seems like one way of doing this, but the only examples I can find seem to assume there are two different processes on seperate threads, not one process being repeated.

View 4 Replies

.NET 2010 : Pause It By Clicking On A "pause" Button In The Development Environment?

Jul 21, 2011

I have an app that I'm debugging and I need to pause it by clicking on a "pause" button in the development environment. I don't want to stop it programmatically, just manually to check what it is doing. I know this should be simple but I can't find a pause button anywhere on the toolbar.

View 4 Replies

VS 2010 Error - Cross-Thread Operation Not Valid: Control TbPlaca1 Accessed From A Thread Other Than The Thread It Was Created On

Aug 13, 2010

In one application, I need use 4 simultaneous threads.When the threads finished, I need to update the text of a TextBox.So, I create 4 Textbox, and I wanna the threads change the text to FINISHED.Each thread change one distinct TB.I use this "example"

Dim Terminados As Integer = 0
Private Sub frmEnviarMensagem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Start()

[code]....

The problem is, I have an error in the red lines.The error is: INVALIDOPERATIONEXCEPTION "Cross-Thread operation not valid: Control tbPlaca1 Accessed from a thread other than the thread it was created on."I don't use cross threading. Each TB only was accessed for the correspondent thread, and for the "main program".

View 3 Replies







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