|
-
Aug 25th, 2004, 11:45 AM
#1
Thread Starter
Hyperactive Member
Ending application with busy threads
Hi,
having WindowsForm application, if I do Application.Exit() and some threads are running, the main GUI terminates, but the VS IDE stays in run mode keeping these threads running.
How to properly exit my application if it hase more threads? I can't find way to exit or terminate the thread, especially if it is busy with external code (eg. blocked by Socket blocking methods).
Thanks
-
Aug 25th, 2004, 05:02 PM
#2
Sleep mode
Can't you just use terminate it with Abort method of the running thread . You'd probably need to declare this public in a class so you can have a reference to it .
-
Aug 26th, 2004, 04:18 AM
#3
Thread Starter
Hyperactive Member
Well, in the documentation about Abort() method is written: Calling this method usually terminates the thread.
It only queues the request to terminate, which you can even cancel by calling Thread.ResetAbort().
And if the thread is blocked waiting for response, this does not work.
---
PS: If I terminate the thread, do all it's resources become free?
-
Aug 27th, 2004, 07:56 PM
#4
Hyperactive Member
How about using. Application.ExitThread();
..::[ kleptos]::..
- Database Administrator (MSSQL 2000)
- Application Developer (C#)
- Web Developer (ASP.NET)

-
Aug 28th, 2004, 04:04 AM
#5
Thread Starter
Hyperactive Member
Nope, this does not work.
And in MSDN, about Application.Exit() is written:
This method does not force the application to exit. The Exit method is typically called from within a message loop, and forces Run to return. To exit a message loop for the current thread only, call ExitThread.
So this is just what I don't need, I need all threads to terminate. Just try it!
PHP Code:
using System.Net;
using System.Threading;
static Thread MyThread;
static Socket MySocket;
[STAThread] static void Main(string[] args)
{
MyThread = new Thread(new ThreadStart(MyThreadProc));
MyThread.Start();
// Application.Run(new MyForm());
}
public static void MyThreadProc()
{
TcpListener MyListener = new TcpListener(IPAddress.Parse("127.0.0.1"),10000);
MyListener.Start();
}
// private static void MyForm_Load(object sender, EventArgs e)
// {
// Application.Exit();
// }
As you can see, I only exit the message loop for the loaded form, which continues the code after Application.Run(). This exits [STAThread] and returns to IDE, but it's still in run mode and I need to click stop button in order to really exit from my app.
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
|