473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Threading and subroutines

I have a class, ProcessFiles, with several subroutines it runs for each type
of file I want to "process."

First, I check directories for files. Then, based on the filenames of those
I find in the directory, I do IP address lookups from a database to see
where these files need to be sent. After I lookup the IP addresses, I
dimension a new class (ProcessThreads), and call ProcessThreads.Process for
each IP I pull out of the database. In psuedo code it looks like:

Private Sub ProcessUsers()

For each filename in FileList
Open database connection, and retrieve a list of IP's

Do while rs.read()
Add IP address to an array
Loop

If IPArray(0) <> "" Then
Dim ProcessThreads as New ProcessThreads
ProcessThreads.Process(FileName, IPArray)
End If

Next

End Sub

In ProcessThreads, it adds an instance of a new class to a threadpool, which
actually does the transfer of files, etc... ProcessThreads also keeps track
of the threads it calls, via some sample code I found elsewhere.

However, I'm curious about the above code. Each time I call ProcessThreads,
will this part of the program stall until that instance of the
ProcessThreads.Process routine finishes, or will this actually do what I
want it to, and call several instances of ProcessThreads at once (or right
in a row, really)?

-Jason
Nov 21 '05 #1
3 1348

"OpticTygre" <op********@adelphia.net> wrote
I have a class, ProcessFiles, with several subroutines it runs for each type
of file I want to "process." However, I'm curious about the above code. Each time I call ProcessThreads,
will this part of the program stall until that instance of the
ProcessThreads.Process routine finishes, or will this actually do what I
want it to, and call several instances of ProcessThreads at once (or right
in a row, really)?


You really haven't supplied enough information to answer your question.
You didn't post the code for ProcessThreads.Process so it is impossible
to tell what it will do...

If a kid brings home a bag of candy, will the mom find a Milky Way bar?
You really can't know until you dump out the bag, and examine the contents!
<g>

Also be aware that you don't gain CPU cycles (or network capacity) by adding
threads. In fact you take a few cycles away because of the management overhead.
You might want to think about using some sort of Queue such that only a few
threads are needed at a time, and the few background threads work on processing
whatever is in the queue, until it is emptied.
LFS
Nov 21 '05 #2
What you stated is almost what I'm doing. The ProcessThreads.Process looks
something like this:

Public Sub Process(ByVal FileList() As String, ByVal IPArray() As String)
Dim n As Integer = 0

blnUploadingFiles = True

For n = 0 To IPArray.Length - 1
Dim Worker As New SFTPUpload
Worker.FileName = FileList
Worker.IPAddress = IPArray(n)
Worker.Password = SFTPParams.Password
Worker.Port = SFTPParams.Port
Worker.ThreadID = _workerID
Worker.Username = SFTPParams.UserName
_workerID += 1

Worker.OnWorkerStart = AddressOf Me.WorkerStart
Worker.OnWorkerEnd = AddressOf Me.WorkerEnd

Worker.Upload()
Next

'Wait until at least one thread has fully started
Do Until ((_completeWorkerList.Count > 0) Or
(_activeWorkerList.Count > 0))
Application.DoEvents()
Loop

'While the threads are working, check to see if someone turned off
the uploads,
'or see if there are new files. If there are new files, exit all
threads, and
'let the main timer tick again to load the new files and start the
threads over.

Do While ((_completeWorkerList.Count > 0) Or
(_activeWorkerList.Count > 0))
If m_ProcessUploads = Definitions.UploadProcessState.Stopped
Then
Call CloseThreads()
blnUploadingFiles = False
Exit Sub
End If

If CheckForNewFiles(FileList) = True Then
'Cancel all threads
Call CloseThreads()

Do Until _activeWorkerList.Count = 0
'Waiting for active threads to finish
Application.DoEvents()
Loop

blnUploadingFiles = False
Exit Sub 'Wait for the next timer tick and start the process
all over
End If
Application.DoEvents()
Loop

'Delete all files that were uploaded previously to the machines
Call DeleteUploadedFiles(FileList)

'Finished uploading files. Allow the timer to call this procedure
again
'if it needs to.
blnUploadingFiles = False

End Sub

Keep in mind, this code is still kindof ugly due to lack of time to clean it
up. There are some other subroutines in the class that handle adding and
removing the worker threads of the SFTPUpload class to the list, checking
for new files, deleting all successfully uploaded files, etc... But
basically, the ProcessThreads class initiates the SFTPUpload class into
different threads for each IP, and waits for them to either finish
successfully or be cancelled by the user. What I'm wondering, is that in
the ProcessFiles class, will it stall if I try and call multiple instances
of this class in a For..Next loop like I was doing? Btw, I'm using a
threadpool in the SFTPUpload class as a queue for my worker objects.

-Jason

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"OpticTygre" <op********@adelphia.net> wrote
I have a class, ProcessFiles, with several subroutines it runs for each
type
of file I want to "process."

However, I'm curious about the above code. Each time I call
ProcessThreads,
will this part of the program stall until that instance of the
ProcessThreads.Process routine finishes, or will this actually do what I
want it to, and call several instances of ProcessThreads at once (or
right
in a row, really)?


You really haven't supplied enough information to answer your question.
You didn't post the code for ProcessThreads.Process so it is impossible
to tell what it will do...

If a kid brings home a bag of candy, will the mom find a Milky Way bar?
You really can't know until you dump out the bag, and examine the
contents!
<g>

Also be aware that you don't gain CPU cycles (or network capacity) by
adding
threads. In fact you take a few cycles away because of the management
overhead.
You might want to think about using some sort of Queue such that only a
few
threads are needed at a time, and the few background threads work on
processing
whatever is in the queue, until it is emptied.
LFS

Nov 21 '05 #3

"OpticTygre" <op********@adelphia.net> wrote
Do While ((_completeWorkerList.Count > 0) Or (_activeWorkerList.Count > 0)) <...> Application.DoEvents()
Loop What I'm wondering, is that in
the ProcessFiles class, will it stall if I try and call multiple instances
of this class in a For..Next loop like I was doing? Btw, I'm using a
threadpool in the SFTPUpload class as a queue for my worker objects.


From just a quick scan, it looks to me like the first time you call Process,
your calling code will be blocked until the above loop exits....

LFS

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Microsoft | last post by:
I'm not sure where to physically place my subroutines in vb.net I get namespace and not declared errors... Imports System Imports System.Management Public Class Form1
5
by: OpticTygre | last post by:
Heheh...I've got lots of questions today. If I have a loop that calls the same subroutine several times (that subroutine may be processor and network intensive): For i = 1 to 100 Call...
14
by: Simon Verona | last post by:
I think I'm doing this wrong : I have a class with a public shared method such as follows: public shared sub myFunction dim frm as new myFrm dim t as new Threading.Thread(Addressof ...
10
by: liz0001 | last post by:
Hi, I need to access an .asp subroutine file from a subdomain. i.e. the website is at www.domain.com and I want to access the same subroutines on the subdomain mobile.domain.com. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.