472,331 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 9134

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Harald Armin Massa | last post by:
I need to do some synchronisations like in a cron.job import time from threading import Thread class updater(Thread): def run(self): while...
1
by: Peter Steele | last post by:
Okay, I assume I'm missing something obvious here. I have created a simple service in C# that on starting spawns a thread to do some processing. The...
3
by: Niyazi | last post by:
Hi, I created application that I get information from AS400 for reporting. In main.exe has only 1 frm which calls (as a class library)...
2
by: Prasad | last post by:
Hi, I am writing a service which takes a long time to stop after the OnStop call is given by the Services Snap-in. The problem is I cannot cut down...
8
by: Tim Bücker | last post by:
Following scenario: The user opens a form, a thread is started to play a sound ... public void playSoundUsingThread() { if...
26
by: Ricardo | last post by:
I made a program that generate random numbers and put it in a listbox when the user click go. The problem is: how can i made a button stop, to stop...
3
by: Saizan | last post by:
I embedded an Rpyc threaded server in a preexistent daemon (an irc bot), this is actually very simple; start_threaded_server(port = DEFAULT_PORT)...
9
by: Jon Slaughter | last post by:
I'm using Thread and ThreadStart to create a thread for testing purposes and I do not want to use a pool because the thread exists for the life time...
0
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I have a windows application that does not stop running whenever the application exits. Could someone fill me in on what I am doing wrong? ...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.