tags:

views:

153

answers:

1

I have two processes both developed in C#.

One of them is a Windows Service, the other one a normal windows based application.

What I intend to do is to exit the application from Service,

I don't intend to kill it forcibly, which i am able to do. I want to exit it gracefully.

Can i call the application_close function defined in my application through the service.

+3  A: 

Process.CloseMainWindow() is what you're looking for, I believe.

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.closemainwindow.aspx

Edit: If you really want to implement IPC, I've found utilizing message queues to be the most easily-implemented solution in windows, but even that isn't very simple, and I wouldn't recommend it when all you want is resource cleanup on exit.

Tanzelax
@Tanzelax that seems write, let me re-edit the question, is there someway i can call a function defined in the process, that does all house-keeping before closing the process
Kazoom
Whihle there isn't an easy way to call arbitrary code without actually implementing IPC, CloseMainWindow will essentially be the same as sending the alt-F4 to your windows app. If your application has proper disposal handling in its main form's Dispose or whatever, that should be good enough for this usage.
Tanzelax
@Tanzelax thankx, is there an usage example i can find
Kazoom