469,927 Members | 1,876 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Cant Stop A Thread

VB 2003. I cant find the last thing im missing.
I click the "Run" button to run my app in VB.net and it runs.
But when i close the application, the thread does not end ( i think )
because it never ends the debuger
and i have to hit the "little square" to stop the app.

If make a shortcut to the exe and run it that way, it stays in the Windows
Task Manager and I have to kill the process.

Has anyone else run into this / work around?

My thread opens a udp port and listens for data on a port. ( but i dont
think that matters )
For the example I used to create this, it is:
http://www.codeproject.com/vb/net/UDP_Send_Receive.asp
On FormLoad i open a new thread:
ThreadReceive = _
New System.Threading.Thread(AddressOf A_Sub )
ThreadReceive.Start()

===
then in the
Public Sub A_Sub
'I do stuff
EndSub

===
Then on form Close I call
MessageBox.Show( "yes i am closing the application" )
ThreadReceive.Suspend() 'Both of these or just 1 of these alone does not
work
ThreadReceive.Abort()
messagebox.show( "the thread should have stopped but it didnt and the app is
still in Windows Task Manager and never leaves the debuger." )
Thanks,

Miro
Aug 4 '06 #1
2 9012

Miro wrote:
VB 2003. I cant find the last thing im missing.
I click the "Run" button to run my app in VB.net and it runs.
But when i close the application, the thread does not end ( i think )
because it never ends the debuger
and i have to hit the "little square" to stop the app.

If make a shortcut to the exe and run it that way, it stays in the Windows
Task Manager and I have to kill the process.

Has anyone else run into this / work around?

My thread opens a udp port and listens for data on a port. ( but i dont
think that matters )
For the example I used to create this, it is:
http://www.codeproject.com/vb/net/UDP_Send_Receive.asp
Actually, if your using blocking socket calls (ReceiveFrom?) then it
does matter. A call to Thread.Abort is only a request, it doesn't
guarentee that a thread will immediately exit. The problem with the
blocking socket calls is at the low level, they are actually calling
out into unmanaged code - and so the ThreadAbortException is not thrown
until the call returns (look at the docs for a more detailed
explanation). The way I usually handle this is simply close the
socket. This causes the blocking read to return, and then you can exit
the thread...

--
Tom Shelton [MVP]

Aug 4 '06 #2
Yes that worked.

Thank you Tom.

I though the socket and the UDP thread were one in the same and once set up
were interlinked.

Socket.close()
Thread.abort() ' works perfectly now

Thanks again.

Miro

"Tom Shelton" <to*@mtogden.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
>
Miro wrote:
>VB 2003. I cant find the last thing im missing.
I click the "Run" button to run my app in VB.net and it runs.
But when i close the application, the thread does not end ( i think )
because it never ends the debuger
and i have to hit the "little square" to stop the app.

If make a shortcut to the exe and run it that way, it stays in the
Windows
Task Manager and I have to kill the process.

Has anyone else run into this / work around?

My thread opens a udp port and listens for data on a port. ( but i dont
think that matters )
For the example I used to create this, it is:
http://www.codeproject.com/vb/net/UDP_Send_Receive.asp

Actually, if your using blocking socket calls (ReceiveFrom?) then it
does matter. A call to Thread.Abort is only a request, it doesn't
guarentee that a thread will immediately exit. The problem with the
blocking socket calls is at the low level, they are actually calling
out into unmanaged code - and so the ThreadAbortException is not thrown
until the call returns (look at the docs for a more detailed
explanation). The way I usually handle this is simply close the
socket. This causes the blocking read to return, and then you can exit
the thread...

--
Tom Shelton [MVP]

Aug 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Harald Armin Massa | last post: by
1 post views Thread by Peter Steele | last post: by
3 posts views Thread by Niyazi | last post: by
8 posts views Thread by Tim Bücker | last post: by
26 posts views Thread by Ricardo | last post: by
3 posts views Thread by Saizan | last post: by
9 posts views Thread by Jon Slaughter | last post: by
reply views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.