Re: C# Console app with hidden window and user input

Tech-Archive recommends: Speed Up your PC by fixing your registry



Dilip <rdilipk@xxxxxxxxx> wrote:
So I am trying to work backwards by converting that application to a
console app but w/the console window hidden.

But why not a Windows Forms app that doesn't show any forms? That
sounds like the way forward.

You are not going to believe this but the only reason why this app was
made a service was because the original team did not want it popping
up a console window. In all respects this app was born as a console
app and it does nothing that would bestow the boon of being a service
on it (for example it doesnt and cannot run while there is no user
logged on). So in reality, when the app is under development we
usually use it as a console app which just waits on a console.readline
statement. The reason its waiting on that statement is because after
the user hits enter (or whatever) the app executes clean up code AND
pulls down the UI app (that it launched on start up) at the same
time. On deployment it gets installed as a service and an external
batch script just starts and stops it using the SCM. OnStart launches
the UI app, OnStop executes clean up code and shuts down the UI app.

Now, you see where I am going? This app is *already* a console app.
I don't want to get into the hassle of converting it into a winforms
app. I wanted to retain it as a console app but find a way to shut it
down gracefully while the console window remains hidden.

Um, there's no hassle at all. You change the project type - it takes
about 10 seconds to do.

If you're dead set on using a console app, however, you could kill it
by listening on a local socket, and dying whenever something connects
to that socket and sends an appropriate packet.

I guess I could do this too but don't you like the
EventWaitHandle.OpenExisting idea?

That should work, yeah - they're pretty similar solutions.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.


Quantcast