|
-
Jul 21st, 2005, 04:24 PM
#1
Thread Starter
Addicted Member
handle closing of the Concole window
I have Console application. How can I handle closing of the Concole window ?
-
Jul 21st, 2005, 04:39 PM
#2
Re: handle closing of the Concole window
what do you mean?
If you're displaying text and it's closing before you can read it, then you'd just have to put a Console.Readline()
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jul 21st, 2005, 06:03 PM
#3
Re: handle closing of the Concole window
If you run your app in a console window that is already open, that window will remain open when your app exits. Likewise, if your app opened a new window in which to run that window will be closed when your app exits. In the second case, to avoid the window closing without warning the user, take MrPolite's advice, perhaps preceeded with Console.Write("Press ENTER to exit.").
-
Jul 21st, 2005, 08:25 PM
#4
Fanatic Member
Re: handle closing of the Concole window
I guess he/she meant the cmd.exe Window. He/She wants to check that the Windows is being closed explicitly by the user to avoid loss of information on his/her program running in console mode. I guess we don't have access to knowing this thing. Windows starts it as a thread.
Or we can get the thread ID of this one and remember it when Windows tries to kill it?
-
Jul 24th, 2005, 07:55 AM
#5
Thread Starter
Addicted Member
Re: handle closing of the Concole window
 Originally Posted by MrPolite
what do you mean?
If you're displaying text and it's closing before you can read it, then you'd just have to put a Console.Readline()
I have Console application. Sometimes my application prints something using Console.WriteLine. I want to handle closing of my application by user pressing
on X at top right corner of the Console window. I want to execute any code before my application closes.
-
Jul 24th, 2005, 01:55 PM
#6
Re: handle closing of the Concole window
well the reason the window closes is because you application has finished. If you run cmd.exe and then run your program from there, you'll notice that the window wont close by itself (becuase when your program finishes running, it returns to cmd.exe and cmd.exe is still running).
As suggested before, you can do a Console.ReadLine() at the end.
(you could do that in a while-loop also )
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jul 24th, 2005, 07:43 PM
#7
Re: handle closing of the Concole window
As far as I'm aware you're console app has no actual awareness of the window it's running in. If the user closes a console window using that close button before the app has finished execution then, frankly, they're an idiot and deserve to lose their data.
-
Jul 24th, 2005, 08:06 PM
#8
Frenzied Member
Re: handle closing of the Concole window
they're an idiot and deserve to lose their data.
That's why we say "All user's are loosers".
You got to think of users as a bunch of overactive kids that will break anything that can be broken.
One just have to keep Murphy's law in mind when developing applications.
There must be a way one can attach to a window and receive some event notification as it is closed. Before it was done with API, I'm sure. I don't have it on my machine now, but look in APIViewer if you got it.
-
Jul 25th, 2005, 06:54 AM
#9
Re: handle closing of the Concole window
*Ahem*
use this event (fires shortly before a program exits)...
Application.ApplicationExit()
I don't live here any more.
-
Jul 25th, 2005, 07:51 AM
#10
Re: handle closing of the Concole window
 Originally Posted by wossname
*Ahem*
use this event (fires shortly before a program exits)...
Application.ApplicationExit()
But the Application class is a member of the System.Windows.Forms namespace, so I'm not sure that it can be used in a console app. It may be possible, but I don't think it would be in that namespace if it was intended to be used for non WinForms apps.
-
Jul 25th, 2005, 08:08 AM
#11
Re: handle closing of the Concole window
Hmm. Seems you're right about this but I know for a fact that you can use Application.StartUpPath from within a console window because I did it the other day.
Probably because its static.
Hmm (again).
I don't live here any more.
-
Jul 25th, 2005, 06:50 PM
#12
Re: handle closing of the Concole window
I had a quick test and you can add a reference to System.Windows.Forms to a console app with no problems, but the Application.ApplicationExit event doesn't get raised. I tried using AddHandler to attach a procedure to the event in both a WinForms app and a console app and the procedure was executed in WinForms but not the console. Presumably a WinForms app has a tighter connection to that namespace somehow.
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
|