When the program starts, it checks for the amount of threads the user wants to use to download files with. The threads are then created. When the user chooses a file to download, the threads begin grabbing the file until it's fully downloaded.
The problem is, some threads stall right from the start, & just sit there doing nothing.
The global work variable is Sync-Locked, then quickly released by each instance, & to my eyes, there is nothing wrong.
They are all instances of the same class, & do the exact same thing, so why is it that some run, & others don't?
VB.NET is the programming language. They are looping Background workers.
I would really like to know why some run, & others don't.
btw... they have quick non-blocking sleeps, as well as blocking sleeps to allow others the chance to run (proprietary non-blocking DLL).
So all i'm left to think on is that Microsoft's process queuing has some type of bug going on in there someplace.
Can anyone verify this?
...or is there a way to do multiple looping threads where they're guaranteed to run?
Any help will be awesomely appreciated.
2 1647
Did you debug the working-method, if this method is called at all?
Can you provide some code?
Is the amount of running (well working) threads always the same or does it differ when you cloae your program and start it again?
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
Process.GetCurrentProcess.PriorityClass = ProcessPriorityClass.Idle
-
-
Try
-
sServer = GetSetting("Program's Name", "Server Settings", "Server").Trim
-
Catch ex As Exception
-
sServer = ""
-
End Try
-
Try
-
iPort = CInt(Val(GetSetting("Program's Name", "Server Settings", "Port").Trim))
-
If iPort = 0 Then
-
iPort = 119
-
End If
-
Catch ex As Exception
-
iPort = 119
-
End Try
-
Try
-
bIsSSL = GetSetting("Program's Name", "Server Settings", "SSL").Trim
-
Catch ex As Exception
-
bIsSSL = False
-
End Try
-
Try
-
UserConnections = CInt(Val(GetSetting("Program's Name", "Server Settings", "Connections").Trim))
-
If UserConnections = 0 Then
-
UserConnections = 2
-
End If
-
Catch ex As Exception
-
UserConnections = 2
-
End Try
-
Try
-
sUsername = _Decrypt(GetSetting("Program's Name", "Server Settings", "UserName").Trim, GenerateSysKey())
-
Catch ex As Exception
-
sUsername = ""
-
End Try
-
Try
-
sPassword = _Decrypt(GetSetting("Program's Name", "Server Settings", "Password").Trim, GenerateSysKey())
-
Catch ex As Exception
-
sPassword = ""
-
End Try
-
If sServer IsNot "" And sServer IsNot Nothing And UserConnections <> 0 Then
-
_BTCount = UserConnections
-
xBGThread = New Thread(AddressOf ThreadBeginThreads)
-
xBGThread.SetApartmentState(ApartmentState.STA)
-
xBGThread.Priority = ThreadPriority.Lowest
-
xBGThread.IsBackground = True
-
xBGThread.Start()
-
bReadyToConnect = True
-
GoTo 1
-
Else
-
If frmSettings.ShowDialog() = DialogResult.OK Then
-
If sServer IsNot "" And sServer IsNot Nothing Then
-
If iPort <> 0 Then
-
bReadyToConnect = True
-
End If
-
End If
-
End If
-
End If
-
If bReadyToConnect = True Then
-
_BTCount = UserConnections
-
xBGThread = New Thread(AddressOf ThreadBeginThreads)
-
xBGThread.SetApartmentState(ApartmentState.STA)
-
xBGThread.Priority = ThreadPriority.Lowest
-
xBGThread.IsBackground = True
-
xBGThread.Start()
-
End If
-
1:
-
Dim EXfileName As String = Nothing
-
Try
-
If Command() Is Nothing Or Command() = "" Then
-
'No Commandline passed in
-
Else
-
'Deal with Commandline params
-
End If
-
Catch ex As Exception
-
MsgBox(ex.Message & vbCrLf & vbCrLf & Command().Trim)
-
End Try
-
End Sub
-
This is an example of the threads being created: -
Public Sub ThreadBeginThreads()
-
Dim _Count As Integer = _BTCount
-
DLThreads.Clear() ' Global list(Of Integer)
-
For i As Integer = 0 To (_Count - 1)
-
DLThreads.Add(0)
-
Select Case i
-
Case 0
-
BG_Work0.RunWorkerAsync()
-
Case 1
-
BG_Work1.RunWorkerAsync()
-
Case 2
-
BG_Work2.RunWorkerAsync()
-
Case 3
-
BG_Work3.RunWorkerAsync()
-
Case 4
-
BG_Work4.RunWorkerAsync()
-
Case 5
-
BG_Work5.RunWorkerAsync()
-
Case 6
-
BG_Work6.RunWorkerAsync()
-
Case 7 ' And so on...
-
BG_Work7.RunWorkerAsync()
-
End Select
-
Next
-
DLThreads.Add(0)
-
End Sub
-
This is an example of the BG_Work0: -
Public WithEvents _Son0 As TheClassThatDoesTheWork 'Declaration in Form1
-
' And so on...
-
-
Private Sub BG_Work0_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BG_Work0.DoWork
-
_Son0 = New TheClassThatDoesTheWork(0)
-
End Sub
-
This is an example of _Son0 getting fired events from the instance of TheClassThatDoesTheWork(0): -
Private Sub _Son0_WorkerParent_OnTransfer(ByVal ID As Integer, ByVal _SegFileName As String, ByVal _SegPartNumber As Integer, ByVal _MaxSegParts As Integer, ByVal e As _TransferEventArgs) Handles _Son0.WorkerParent_OnTransfer
-
Try
-
' Deal with the event
-
Catch ex As Exception
-
' Deal with Error
-
End Try
-
End Sub
-
This is an example of TheClassThatDoesTheWork(0): -
'Imports required
-
-
Public Class TheClassThatDoesTheWork
-
-
'All the declarations required
-
'All the events
-
-
-
Public Property Terminate_ThreadWorker As Boolean
-
Get
-
Return xTerminateThread
-
End Get
-
Set(ByVal value As Boolean)
-
xTerminateThread = value
-
End Set
-
End Property
-
-
Public Sub New(ByVal xID As Integer)
-
_ID = xID
-
_Worker.Timeout = 30
-
_Worker.NewsServer = sServer
-
_Worker.NewsPort = iPort
-
_Worker.User = sUsername
-
_Worker.Password = sPassword
-
Select Case bIsSSL
-
Case True
-
_Worker.SSLStartMode = sslImplicit
-
Case False
-
_Worker.SSLStartMode = sslNone
-
End Select
-
xThread = New Thread(AddressOf DEngine)
-
xThread.SetApartmentState(ApartmentState.STA)
-
xThread.Priority = ThreadPriority.Lowest
-
xThread.IsBackground = True
-
xThread.Start()
-
End Sub
-
-
Private Sub DEngine()
-
Nap = New TakeNap ' Non-Blocking sleep
-
Do Until _IsClosing = True Or xTerminateThread = True
-
Nap.Sleep(50) ' or Thread.Sleep(50)
-
If SomeVariable > 0 And SomeOtherVariable = False Then
-
Try
-
'Get the file
-
Catch ex As Exception
-
'Report error to user, then...
-
GoTo 1
-
End Try
-
BusyNow = False
-
If CurrentFile = "" Then GoTo 1
-
GC.Collect()
-
ElseIf SomeOtherVariable = True Then
-
Do Until SomeOtherVariable = False
-
Nap.Sleep(50) ' or Thread.Sleep(50)
-
Loop
-
ElseIf SomeVariable < 1 And SomeOtherVariable = True Then
-
' do stuff
-
End If
-
1:
-
If PAUSED_STOPPED = True Then
-
BusyNow = False
-
End If
-
If _Worker.Connected = False Then
-
BusyNow = False
-
-
Try
-
_Worker.Connect()
-
Catch ex As Exception
-
' Fire an event
-
End Try
-
End If
-
Loop
-
End Sub
-
-
'All required Subs, & Functions
-
-
Protected Overrides Sub Finalize()
-
MyBase.Finalize()
-
End Sub
-
End Class
-
This was posted to C# instead of VB.NET, but it's basically the same theory, at least that's what other C-Sharpers have told me.
Sorry for the mistake though.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lane LiaBraaten |
last post by:
I am developing a GUI that uses multiple threading.Threads, and Queue.Queues
for communicating between the threads, and threading.Timers for checking the
queues.
Everything works well (runs to...
|
by: Jon Skeet [C# MVP] |
last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the
article on all the groups this is posted to.
I've finally managed to finish my article on multi-threading - at least
for...
|
by: Frank Rizzo |
last post by:
Hello,
I have a class with all static methods that is called by multiple
threads. I was wondering what effect that has on the competing threads.
Does Thread2 have to wait until Thread1 is done...
|
by: Arafangion |
last post by:
Hello, recently I've been trying to figure out how the heck to just
destroy a thread.
I have since rewritten the code in question, but what I was trying to do
was to use the .Abort() method, but...
|
by: OpticTygre |
last post by:
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...
|
by: Stressed Out Developer |
last post by:
We have an application that has a 200 count loop that does the following:
' Each time thru the loop we pass the next IP Address is a range (aka
192.168.4.50 thru 192.168.4.254)
Try
If...
|
by: WXS |
last post by:
When I see things in .NET 2.0 like obsoletion of suspend/resume because of
the public reason MS gives of they think people are using them
inappropriately.. use mutex, monitor and other...
|
by: Zerge |
last post by:
I can launch threads just fine, but then I have to do a time.sleep(n)
so the main thread from which they where launched will wait for all
the threads to return.
How can I detect when all threads...
|
by: Dann Corbit |
last post by:
Rather than create a new way of doing things:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html
why not just pick up ACE into the existing standard:...
|
by: S James S Stapleton |
last post by:
Is volatile necessary anymore? I have a two-thread piece of code I've been
testing to figure out what volatile does (fairly simple code, uses
pthreads). I have an update thread (variables passed as...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |