Force a Windows Form application to exit.

  • Thread starter Thread starter Andrea Valori
  • Start date Start date
A

Andrea Valori

Hi everyone,
I've a problem with a .NET VisualBasic 2005 Windows Form application. My app
uses the Bluetooth to sends messages to mobile devices in its BT coverage
area; for every device founded, its create a managed thread which takes care
of the communication between the mobile device and my app. If I try to end my
application while some thread is alive (please note that I call a
thread.abort for every alive thread before end) sometimes my app hangs up
because some thread remains alive regardless the thread.abort call ( I know
that this method closes the thread only if it is in a safe point for the
framework). Any idea to force the end of the app regardless that threads?
Thanks in advance, Andrea Valori.
 
Hi Andrea,

That's no good idea to do it, becasue you need to manage opened threads knowing
what they are doing. Anyway, you can do it declaring the thread as backgrounded
(.IsBackground=true);
In this way if main (UI) thread exits the application finishes.

Regards,
Alex Meleta
[Tech Blog: http://devkids.blogspot.com]

AV> Hi everyone,
AV> I've a problem with a .NET VisualBasic 2005 Windows Form
AV> application. My app
AV> uses the Bluetooth to sends messages to mobile devices in its BT
AV> coverage
AV> area; for every device founded, its create a managed thread which
AV> takes care
AV> of the communication between the mobile device and my app. If I try
AV> to end my
AV> application while some thread is alive (please note that I call a
AV> thread.abort for every alive thread before end) sometimes my app
AV> hangs up
AV> because some thread remains alive regardless the thread.abort call (
AV> I know
AV> that this method closes the thread only if it is in a safe point for
AV> the
AV> framework). Any idea to force the end of the app regardless that
AV> threads?
AV> Thanks in advance, Andrea Valori.
 
Hi Alex,
thanks for your reply. Really, I've added the property t.IsBackground=true
before my post but it seems not useful for my problem. When I exit of my app,
I save my settings, call t.abort if I have some open threads and after I call
System.Environment.Exit(0) or System.Application.Exit but nothing is useful.
Sometimes my app hangs up until the thread finish his work (regardless the
t.abort) and after closes. Any new idea?
Thanks to all,
Andrea Valori.
 
Back
Top