473,857 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Threadin g.Thread(Addres sOf A_Sub )
ThreadReceive.S tart()

===
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.S uspend() 'Both of these or just 1 of these alone does not
work
ThreadReceive.A bort()
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 9256

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 ThreadAbortExce ption 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.co mwrote in message
news:11******** **************@ s13g2000cwa.goo glegroups.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 ThreadAbortExce ption 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
2423
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 True: do_updates() time.sleep(600)
1
363
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 service can be stopped with a "net stop" command of course, but under some circumstances the service will decide to terminate itself. My OnStart looks something like this: protected override void OnStart(string args) { serviceThread = new Thread(new ThreadStart(ServiceThreadStart));...
3
1725
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) CLS_MAIN.dll. The CLS_MAIN.dll get the tables from AS400 and stores it in Dataset. Then returns to main frm then main frm calls the FirstReport.dll. The FirstReport.dll get the information from access database and creates the sqkl string and works with dataset and then writes in pre-formated Excel sheet.
2
2867
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 on the time that it takes to Stop. The Service snap-in gives me the error saying that the service did not respond to the Stop call in a timely fashion. So is there any method by which I can get around this problem. Thanks Prasad
8
2317
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 (File.Exists(fileLocation)) PlaySound(fileLocation, 0, 0); // winmm.dll }
26
4714
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 the method that is running??? s...
3
5772
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) then I had the necessity to stop the thread which accept() new connections without killing the whole app, the thread is simply a while True that spawn a new thread which serves each connection, so I placed a flag and a break in this way: def local_threaded_server(port = DEFAULT_PORT, **kw):...
9
4008
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 of the app. Eventually I might move on to using pools but at this point I'm just testing some timing issues. in any cause the thread is simply a counter, static void counter()
0
1330
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? Here is the relevant code: ================================= Private m_thTCP As Thread Private m_listener As TcpListener
0
9768
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11083
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10711
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7940
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7104
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.