|
-
Jan 3rd, 2009, 12:03 PM
#1
Thread Starter
New Member
Thread problem!!Help me
I have code like below:
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
Try
DO something
Dim th1 As New Thread(AddressOf ThreadStart)
th1.IsBackground = True
'End If
th1.Start()
Catch ex As Exception
DO something
End Try
End Sub
When I click Button, as thread starts by th1.start, it starts thread without ending btnConnect_Click.
It starts thread, executes few statements of "ThreadStart" and then come back to btnConnect_Click and ends it then again move to thread "ThreadStart" , execute few statement and terminate without any prompt/error.
Can anyone help me.
Thanks.
Last edited by memo421; Jan 3rd, 2009 at 12:09 PM.
-
Jan 3rd, 2009, 12:44 PM
#2
Re: Thread problem!!Help me
What are you doing in ThreadStart?
-
Jan 3rd, 2009, 03:11 PM
#3
Thread Starter
New Member
Re: Thread problem!!Help me
I am willing code execution in this way:
1. Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
2.
3.
Try
4.
Do all the button click function here and after that call the thread
5.
Dim th1 As New Thread(AddressOf ThreadStart)
6.
th1.IsBackground = True
7.
th1.Start()
8. th1.Join()
Catch ex As Exception
DO something
9. End Try
10. End Sub
11. Private Sub Thread()
12. Do Something
13. end sub
-
Jan 3rd, 2009, 03:38 PM
#4
Re: Thread problem!!Help me
Why do you not show us your real code?
-
Jan 3rd, 2009, 04:19 PM
#5
Re: Thread problem!!Help me
I see that Join you have in there, but it wasn't in the first snippet. Was the first snippet real code, or was that left out?
My usual boring signature: Nothing
 
-
Jan 3rd, 2009, 05:36 PM
#6
Re: Thread problem!!Help me
Based on his description, i'll bet that th1.Join() is in his code.
memo, th1.Join() causes your current thread to spinwait until the other thread has finished its work. It then continues from that line. That's why your function is not exiting. Why are you using Join()?
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
|