Create A Loop That Will Declare And Start Multiple Threads?

May 30, 2011

Basically with the code below I would like to create multiple threads. Let's say user input was the number 100 for the "userVal" variable of type integer. With the first pass of the loop, starting with 1, I would like to[code]...

View 10 Replies


ADVERTISEMENT

Start Multiple Threads But Not A Specific Number?

Dec 3, 2009

I want to start multiple threads but not a specific number. For example;

private sub do_sth
...
end sub

[Code]....

View 1 Replies

Create Many Objects (threads) In Loop?

Jun 17, 2011

threads that watch folders and process files. This works fine, but every time needs change to add a new folder or just change some existing rules I have to go in and change the program. I want to builda front end that storesprocessing infofor each watchfolder. The program would then read the configs and build the threads based on them. I cannot find a way to loop through creating the threads.

View 8 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

Create Multiple Threads To Improve A Function On Program

Sep 7, 2011

i need to create multiple threads to improve a function on my program. it is a simple thing really but it's slow and if multithreaded it can improve the speed some thousand times. my program uses a dll to check the MX record of an e-mail from a textbox called emails if the mx record is correct then it validates that domain, if not, it sends to an error textbox with that mail my problem is that im reading a lot on multithreading and i dont have an idea how to make something like this: for x=0 to emails.lines.count -1' start a thread that runs my function next if i can limit the number of threads to avoid crashing it would be good.

View 5 Replies

Multiple Forms - Declare And Instantiate Second Form On Program Start - Use Button Simply To Show Form?

Jan 14, 2010

I have a program that uses two forms. The program opens to the Main form, and the user can navigate to the other form from the Main form through use of a button. Here's the way I've currently written it: When the Main form loads, it declares and instantiates the other form during the load procedure. When the user presses a button, the second form is displayed by means of the ShowDialog method. On the second form, there is a Return to Main Screen button which closes the second form, bringing the user back to the Main form.

So, here's the structure of the code:

Code:
Public Class frmMainForm

Dim frmSecondForm As New SecondForm

Private Sub btnSecondForm_Click(blah, blah, blah) Handles blah, blah, blah

[CODE]...

Here's my reasoning: Originally, I wrote the code so that a new instance of the second form was created every time the button was pressed. The problem was that whatever data was displayed on the second form, previously, was lost when the user returned to it a second time. Since the user would be switching back and forth between these forms, frequently, I needed that data to persist.

What is the best practice for accomplishing this:

1) Declare and instantiate the second form on program start, as I have done, and use the button simply to show the form?

2) Declare and instantiate the second form each time the button is pressed but maintain the variables on the Main form and pass them ByRef to a custom constructor for the second form? Is this even possible?

3) Something else?

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

Loop To Create Multiple Series In Chart Control

May 12, 2012

I am trying to build a function that returns a chart. I want to have a parameter to account for times where i may need more than one series. How does one loop through to create multiple series? I would think you would need a variable for each series. The function is below. I would think that if there were 5 series that each of the "Dataseries" variables should have their own name. Do I then refer to them by index only?

[Code]...

View 1 Replies

Loop To Create Multiple Series In Chart Control?

Jan 15, 2009

I am trying to build a function that returns a chart. I want to have a parameter toaccount for times where i may need more than one series. How does one loop through to createmultiple series? I would think you would need a variable for each series. The function is below. I would think that if there were 5 series that each of the "Dataseries" variables should have their own name. Do I then refer to them by index only? Public Shared Function MakeChart(ByVal form As Form, Optional ByVal numseries As Integer = 0) As Chart

' Add any initialization after the InitializeComponent() call.
Dim SampleChart As Chart = New Chart()
Dim MainChartArea As ChartArea = New ChartArea()

[code].....

View 11 Replies

Pass Multiple Parameters To Multiple Threads?

Sep 15, 2011

I have a loop that creates several threads as such[code]...

View 1 Replies

.net - Doesn't Media.SoundPlayer.Play() Actually Start A Two New Threads, When Called Twice?

Mar 9, 2011

I'm writing a simple little program in VB.NET that has to play two sounds - at the same time.The problem is, that when I call SoundPlayer.Play() twice in immediate succesion, it seems that the latter call sorts of "takes over" the thread that is created by the first call, instead of creating a new one, like it says it should do in the docs.I'm using the following code:

Private Sub Button_OFD_Sound1_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_OFD_Sound1_Browse.Click
LoadSound(OFD_Sound1, TextBox_OFD_Sound1_SelectedFile, SoundPlayer_Sound1)
End Sub

[Code]...

View 1 Replies

VS 2008 Manage / Start Two Threads Which Read Some Elements In An Array

Jun 5, 2010

I have a function which does some processing. Lets name that function DoWork. This function takes some inputs as structure and a string. Now I want to start two threads which would read some elements in an array and then call DoWork with some data and value of that element. DoWork would do processing and thats it. I want two threads to run side by sid.

So I tried to write code but kinda failed. I wrote a function which starts a thread and calls DoWork. Now DoWork accepts structure and string etc. But when we do say abcthread = new threadig.thread(addressof <sub name>). here we cant pass any-value except object. That was first problem.

Anyway, main problem is after the thread has finished processing DoWork, how do I find that out and tell that thread to take another element from array and start again. This has to be managed for both the threads. I need to find out which thread has finished first and tell it to start again with another value. I have usually used one thread but not two in this way.

View 15 Replies

Creating And Starting Threads In A Loop With Parameters

Apr 29, 2010

I have ran into a situation where it would be a lot faster to create a thread by the users demand. Basically, what I have is some kind of downloading program which grabs URLs from the clipboard into a DataGridView. Now when multiple URL's have been added, it becomes really inefficient since only one URL is being processed at a time.Now what I wanted to do is, create a thread for each URL. The parameter for each thread are the URLs which are stored as strings inside the DataGridView rows.[code]

View 3 Replies

Multithreading - Speed Up Loop Through Additional Threads?

Dec 27, 2010

I have problem with multithreading.

For:

Code:

and multithreading to loop for:

Code:

How can I speed up this loop through additional threads?

I tried:

Code:

How can I do?

View 10 Replies

VS 2008 - Use Threads In Loop To Make The Application Less CPU-intensive?

May 4, 2009

I am trying to stop the following piece of code from taking up too much processing power of the PC by using threads. But I keep getting errors when I use threads:

[Code]...

View 3 Replies

.net - Using GDI+ With Multiple Threads?

Apr 18, 2010

it would be best if I just copy and pasted the code (it's very trivial).

Private Sub Main() Handles MyBase.Shown
timer.Interval = 10
timer.Enabled = True
End Sub

[code]....

An exception, "The object is currently in use elsewhere", is raised during the tick event.

View 1 Replies

Start Button Loop A BackgroundWorker With Sleep OracleConnection Results After Each Loop Till Stop Button

May 29, 2012

I have this little application that runs a SQL query works great, now I want to have a Start Button run the and display results then System.Threading.Thread.Sleep(300 * 1000) for 5 min then run again and display results and loop till I buttonstop_click. unsure if the sleep is the best method.

[Code]...

View 2 Replies

How To Run Multiple Threads With BackgroundWorker

Jan 13, 2010

I am writing a project in Visual Basic where I need to run several instances of the same method in parallel. I can do this using BackgrooundWorker by having several (4) copies of my code module (modules 1, 2, 3 and 4) with a call to background worker in each. I then have a Main form which invoke the 4 modules which setup 4 simultaneous background threads. Seeing as the code is the same I want to simply invoke the same module 4 times.

However when I do this I get an error from Backgroounworker that it is already busy. As I understand it this means that it is being shared. However, I have specifically instantiated it as "private" (private with events worker as new backgroundworker). I have tried running the same code in a Class instead of a Module but unless I make it public I have no way of invoking it from Main. I need to be able to pass each thread data from main for it to work on and if the class is private I cant invoke it.

View 2 Replies

How To Stop Multiple Threads

Nov 6, 2010

This code will show you how I started multiple threads:

For i As Integer = 0 To 10
Dim MyThread As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MySub))
MyThread.Start()
Next

Now I'm trying to stop the threads before closing my application but I don't know how to do that?

View 6 Replies

Run Ffmpeg With Multiple Threads?

Jan 25, 2012

how to convert videos files using vb.net and ffmpeg. But as far as i know we cannot use multiple threads to run same exe file to convert files. Do you know how i can convert multiple videos using one external exe file (ffmpeg)?

I have not tried because my computer time was over. So iam just asking a general doubt whether if we attach it to one process then wouldn't the process get locked? Then can we multi-thread this application or not ?

View 1 Replies

VS 2008 - Multiple Threads - Get Two Value?

Jul 28, 2010

I'm testing here something, but i don't know what's the best way to do this.I have a var that tells the application the number of threads that will be started, inside the thread/function that i call i need to return/get two values i have two sub functions, each one returns an integer.Then in the end i need to sum the values.

Example:
Thread1/Function
SF1 - Returns 2
SF2 - Returns 3

Thread2/Function
SF1 - Returns 1
SF2 - Returns 5

After all threads are over, i get the
SF1Total = 2 + 1 and
SF2Total = 3 + 5.

I'm thinking in using shared vars, and inside the function/subfunctions update the values. It's this a correct way to do it? Other question, the threads are assync, but i need to know when the last one finishes. How do i control this? The order they finish doesn't need to be the order they were called....

View 4 Replies

.net - Update From From Multiple Threads Of The Same Class?

May 31, 2012

I have this class and I have a loop that launches multiple threads from the same class. This is all done from the main form.Now I want to update the richtextbox on the main from these classes.I have tried those begininvokes etc etc and nothing worked, no error but no output as well.Here the code for launching the threads :

Private PingObjects(100000) As Account 'Account is the class and login is the sub in it...
PingObjects(I) = New Account
Threads(I) = New Threading.Thread(AddressOf PingObjects(I).login)

[code]....

And to update the rtb, im using MainForm.log.text = "....." Nothing happens, no error.I have tried using the begin invoker method as well.

View 2 Replies

Creating And Aborting Multiple Threads

Sep 28, 2010

To get pass the cross referencing error when running a thread, I use this code

[Code]...

But the AddressOf doesn't accept parameters... So how do I get pass that? Or is there another way to use delegate?

View 6 Replies

Dividing Work Into Multiple Threads?

Aug 10, 2011

I've read a lot of different questions on SO about multithreaded applications and how to split work up between them, but none really seem to fit what I need for this. Here's how my program currently basically works:

Module Module1
'string X declared out here
Sub Main()

[Code]....

This is only a rough outline of what actually happens in my code by the way.

My problem being that if multiple threads start running Main2(), they're dealing with the same X value as in the other threads. The loop inside of main2 executes multiple times per millisecond, so I can't just stagger the loops. There is often duplication of work done.

How can I properly divide up the work so that the two threads running simultaneously never have the same work to run?

View 3 Replies

Implement Multiple Threads In Application

May 12, 2010

I need help to implement multiple threads in application.Assume ds.table(0) has 5 and sometime 6 rows rows for i=0 to ds.tables(0).rows.count-1.I have to apply multiple threads, means all five/six rows should start at once using thead and "Process 1" .."Process 4" should also handled by threads.This is hierarchy that I have to apply with threads, how can I do it. It is requested to put piece of code so I can understand better.

View 13 Replies

Sharing Data Between Multiple Threads?

Jul 7, 2011

I know a little about threading and delegates, as well as socket programming. I'm working with a VB.NET-compatible SDK called TrueVision3D to create a small online game for me and my friends. The problem is that I cannot for the life of me figure out how to pass data from one thread to another. I've created 2 seperate threads on seperate forms.

The first thread is created on a form titled FrmLogin, and it contains all the socket code. I need to be able to update variables in the second thread, which mainly consists of a render loop. The second thread is created on a form titled FrmMain. I'm not quite sure if it matters what forms the threads are created on, I'm just trying to give as much information about the issue as I can. I've tried using delegates and events to pass information from the thread back to the form it was created on, which works fine, but how do I pass data to the second thread from the first?

View 1 Replies

Sharing Object Over Multiple Threads?

Aug 4, 2010

I have an application that needs to perform a series of different actions at specific points in time.To do this I have a timer with various actions that occur in its tick event.One possible action is to send out a few messages via a serial port and then wait (between 1- 300 mins typically) for the next timer tick.Another possible action is to continuously toggle one of the control lines on the serial port until the next tick (again 1-300 mins).

In most instances, i'm happy for everything to run on the main thread, but in the case of toggling the line endlessly, I thought it better to give it its own thread.My problem is that for the new thread to use the Serial Port, it must open the port. Likewise, it must close it before the main thread can have it back.

Here are 2 code snippets

Private Sub activityTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles activityTimer.Tick
Dim some variables here
activityTimer.Stop()
If speedThread.ThreadState = ThreadState.Running Then

[code]....

View 4 Replies

Using Multiple Threads For Faster Execution?

Jan 27, 2012

I have a map image with data associated with the map indicated by RGB index. The data has been populated into an MS Access database. I imported the information in the database into my program as an array and sorted them to go in the order I want the program to run.

I want the program to find the nearest pixel that has a different color from the incumbent pixel being compared. (Colors are stored as string attributes of object Pixel)

First question: Should I use integers to represent my colors instead of string? Would this make the comparison function run significantly faster?

In order to find the nearest pixel of different color, the program begins with all 8 adjacent pixels around the incumbent. If a nonMatch is not found, it then continues onto the next "degree", and in this fashion, it spirals out from the incumbent pixel until it hits a nonMatch. When found, the color of the nonMatch is saved as an attribute of incumbent. After I find the nonMatch for each of the Pixels, the data is re-inserted into the database

The program accomplishes what I want in the manner I've written it, but it is very very slow. After 24 hours, I am only about 3% through with execution.

Question Two: Does my program behavior sound about right? Is this algorithm you would use if you had to accomplish this task?

Question Three: Would it be appropriate for me to use threads in order to finish execution of the program faster? How exactly does that work?

Question Four: Would it be more "intelligent" for my program to find the nonMatch for each pixel and insert it into the database immediately after finding it? (I'm making a guess that this would be good in multi-threading, because while one record is accessing the database (to insert), another record is accessing the array of pixels (shared global variable in program).

Question Five: If threading is a good idea, I'm guessing I would split the records up into more manageable chunks (i.e. quarters), and have each thread run the same functions for their specified number of records? Am I close at all?

View 3 Replies

VS 2008 Multiple Threads Ending?

Jul 29, 2010

In the same line of this thread Now i have a problem with the control of the ending threads. This is my

vb.net threadsEnded = 0 For j As Integer = 0 To numThreads - 1

[Code]...

Some times the application doesn't finish and if i pause the application i see that the threadEnded var doesn't have the correct value, seems like some thread doesn't update the value of the var.

View 5 Replies

VS 2008 Shared Sub And Multiple Threads?

Sep 4, 2010

I have a created a class, which contains a sub routine.This sub routine, should ideally be accessable by objects which are not members of the class, so I would like to make the sub, a 'shared sub' (call it Sub1).

Question: I am using many threads and there will be possibly 100s of 1000s of threads all wanting to use Sub1 (which is at present, is not shared).At present Sub1 , is not a shared sub, so every time a thread wishes to use Sub1 , I am creating a (dummy) instance of the class and then applying Sub1, to that instance.

My program works flawlessly using the above technique.Question: If I were to turn Sub1 (which is not currently shared) into a shared sub, and directly had various threads calling Sub1, would there be any issues with locking, ie. would it possible for 2 threads to enter that thread and start overwriting variables, which another thread has written to?

NOTE: there are no shared variables/properties in Sub1 and all variables used in Sub1 are declared within the sub itself.

View 7 Replies







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