By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,083 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Process.CloseMainProgram() - not always working

P: 84
Hi Guys,
I am having a problem here and need some urgent help from anyone possible??


I have Application 1 which triggers Application 2. Application 2 runs some checks and if it is validated, it closes Application 1. Hence i need to close Application 1 from Application 2.

Now i have process.CloseMainProgram() in Application 2 which works most of the time, but it sometimes leaves Application 1 running. I have added a WndProc overide in Application 1 to track when it recieved a WM_CLOSE or windows instructions to close the application. Apparently when Application 1 is stuck - there is no WM_CLOSE recieved by it and i am not sure why this happens.

Please help guys - as this is quite urgent and i am running out of ideas.
Jan 26 '09 #1
Share this Question
Share on Google+
4 Replies


P: 40
Have you thought on using named Mutex? Named mutex are unique to the system, so you can use them on communicating between processes.
Jan 27 '09 #2

P: 84
I already used those. Anyways i found a way yo dll import user32.dll and send WM_CLOSE manually - rather than via .Net code.
Jan 27 '09 #3

vekipeki
Expert 100+
P: 229
If Application1 is stuck, then you will hardly be able to close it without using Process.Kill(). But your bigger problem is that your Application shouldn't get stuck in the first place, so consider finding the cause to that problem first.

Using Mutexes to send simple notifications between .NET apps should be a better way to do it than sending windows messages manually. It allows you greater flexibility.

WM_CLOSE closes the application, but one day you might decide that App2 could have more states than just validated/not validated - in that case you could use an extra event which can be processed in App1 (or in any other application -- App2 doesn't even have to know if App1 exists - it only fires an event and continues doing its job).
Jan 27 '09 #4

P: 84
@vekipeki
I agree but the problem i am having is that App1 never hangs. It is just that CloseMainWindow never delivers the close message to App1 [sometimes], so thats why i am sending cutom WM_CLOSE.

Thanks anyways for your help.
Jan 27 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.