|
-
Jan 18th, 2012, 12:01 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Threading Problems
Hello
I have a little problem with threads that it's driving me crazy...
I have this application, that when it starts it needs to check some files in hard drive, check some info from the database, and other things where the user doesn't need to interact, i created some threads in the constructor of the main form to handle this job, but i don't understand why, when i try to run some of the threads (didn't figured out if all or some specific), the code of the constructor runs from the start again...
There's a problem when trying to run multiple threads? I already tried the background worker, the thread class and the result it's always the same...
By the way, i have a splash screen that runs in another thread to update the messages.
The code it's similar to this:
vb.net Code:
Public Sub New()
InitializeSplashScreen()
SplashS.UpdateMessage("First Task...")
...
other tasks in the same thread
...
SplashS.UpdateMessage("First thread...")
ThreadUpdateModels()
...
...
End Sub
vb.net Code:
Private Sub ThreadUpdateModels()
Dim thr As New Thread(AddressOf GeralPDM.GetLatestVersion)
With thr
.IsBackground = True
.Start()
End With
End Sub
Some of the functions used by the threads use other functions than the one called directly from the class, is this the problem?
Can i inside a thread call a another thread, i have a situation that i need to check if a connection it's on, before getting the data, so i use another thread?
Thanks
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Jan 18th, 2012, 12:53 PM
#2
Re: Threading Problems
Code:
Public Sub New()
InitializeSplashScreen()
SplashS.UpdateMessage("First Task...")
...
Please tell me that the New Sub is not from a form called SplashS? What's the name of the class with this code in it?
Last edited by Grimfort; Jan 18th, 2012 at 02:13 PM.
-
Jan 18th, 2012, 01:38 PM
#3
Re: Threading Problems
You seem to have a bit of confusion about threads. A thread is a series of function calls and code. Once you start that thread, any code executed as part of the thread is....well....part of the thread. Multiple threads can access objects that are in scope for all of them, but the functions don't matter. One thread can certainly start another thread, or else you wouldn't be able to have threading, since the UI thread is also a thread. You can raise events on other threads, but that's different.
My usual boring signature: Nothing
 
-
Jan 18th, 2012, 02:51 PM
#4
Thread Starter
Frenzied Member
-
Jan 18th, 2012, 06:05 PM
#5
Re: Threading Problems
It sure sounds like you are creating a new instance of that main form. You wouldn't happen to be using default instances would you?
My usual boring signature: Nothing
 
-
Jan 18th, 2012, 06:07 PM
#6
Thread Starter
Frenzied Member
Re: Threading Problems
No i'm not...
Default instances?!
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Jan 18th, 2012, 06:19 PM
#7
Re: Threading Problems
What does that mean? Are you not sure what default instances are? A default instance is where you don't create a specific instance of a form:
Dim nf As New Form1
nf.Whatever 'Uses a specific instance of Form1
but just use
Form1.Whatever 'Uses the default instance of Form1.
The reason I ask is that it really would be possible for a default instance constructor to behave in an odd way. They are kind of arcane to begin with, and cause plenty of problems.
My usual boring signature: Nothing
 
-
Jan 18th, 2012, 06:26 PM
#8
Thread Starter
Frenzied Member
-
Jan 18th, 2012, 07:53 PM
#9
Re: Threading Problems
You do not have to do anything clever to debug multiple threads. You say that the Sub New is running from the start, which is only possible if you are actually creating another one of these objects. If you stick a breakpoint on the first line of the sub and run it, the second time you hit this breakpoint have a look at the call stack to see why. There is also a threads window to show you the other threads which are all paused when the breakpoint is hit.
-
Jan 19th, 2012, 03:00 AM
#10
Thread Starter
Frenzied Member
Re: Threading Problems
I know how to debug, the problem of the debuging some of the threads it's that one of them uses a recursive function, other it's a loop that reads more than 50k rows of the database....
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Jan 19th, 2012, 05:26 AM
#11
Re: Threading Problems
Why would any of that matter? You can see what is calling what with the call stack and the threading window to work out why your constructor is being called multiple times.
-
Jan 19th, 2012, 06:34 AM
#12
Thread Starter
Frenzied Member
-
Jan 19th, 2012, 10:29 AM
#13
Re: [RESOLVED] Threading Problems
Ha! The default instance rears its ugly head, once again. I wish those things had never been added.
My usual boring signature: Nothing
 
-
Jan 19th, 2012, 10:35 AM
#14
Re: [RESOLVED] Threading Problems
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|