Process.CloseMainProgram() - not always working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alag20
    New Member
    • Apr 2007
    • 84

    Process.CloseMainProgram() - not always working

    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.CloseMa inProgram() 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.
  • artov
    New Member
    • Jul 2008
    • 40

    #2
    Have you thought on using named Mutex? Named mutex are unique to the system, so you can use them on communicating between processes.

    Comment

    • alag20
      New Member
      • Apr 2007
      • 84

      #3
      I already used those. Anyways i found a way yo dll import user32.dll and send WM_CLOSE manually - rather than via .Net code.

      Comment

      • vekipeki
        Recognized Expert New Member
        • Nov 2007
        • 229

        #4
        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).

        Comment

        • alag20
          New Member
          • Apr 2007
          • 84

          #5
          Originally posted by vekipeki
          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).
          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.

          Comment

          Working...