How to close an application completely
-
Hi there, I have a VB MFC that uses a dll for sending, receiving, dispalying and logging data from/to another application the problem is that SOMETIMES when I close the VB window by clicking on X the application goes off ( you do not see it on desktop) but when you open the task manager, you can see that the application is still there. The problem is that it happens just sometimes. Any ideas? It is the way I close the appliaction: Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer) If MsgBox("Are you sure you want to Exit the application?", vbYesNo + vbQuestion, "Application") = vbNo Then Cancel = True End If End Sub Private Sub MDIForm_Terminate() fnWEHostShtdn End Sub Private Sub MDIForm_Unload(Cancel As Integer) If Me.WindowState <> vbMinimized Then SaveSetting App.Title, "Settings", "MainLeft", Me.Left SaveSetting App.Title, "Settings", "MainTop", Me.Top SaveSetting App.Title, "Settings", "MainWidth", Me.Width SaveSetting App.Title, "Settings", "MainHeight", Me.Height End If End Sub The other question is that how I can check if an application is running and if for any reason (even a hard close by user) the application is closed, it reopens itself. Thanks in advanced. Nahitan
-
Hi there, I have a VB MFC that uses a dll for sending, receiving, dispalying and logging data from/to another application the problem is that SOMETIMES when I close the VB window by clicking on X the application goes off ( you do not see it on desktop) but when you open the task manager, you can see that the application is still there. The problem is that it happens just sometimes. Any ideas? It is the way I close the appliaction: Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer) If MsgBox("Are you sure you want to Exit the application?", vbYesNo + vbQuestion, "Application") = vbNo Then Cancel = True End If End Sub Private Sub MDIForm_Terminate() fnWEHostShtdn End Sub Private Sub MDIForm_Unload(Cancel As Integer) If Me.WindowState <> vbMinimized Then SaveSetting App.Title, "Settings", "MainLeft", Me.Left SaveSetting App.Title, "Settings", "MainTop", Me.Top SaveSetting App.Title, "Settings", "MainWidth", Me.Width SaveSetting App.Title, "Settings", "MainHeight", Me.Height End If End Sub The other question is that how I can check if an application is running and if for any reason (even a hard close by user) the application is closed, it reopens itself. Thanks in advanced. Nahitan
This is usually caused by an improper shutdown of a component in your app. Most likely, this would be the .DLL you're using. It's possible that it created a seperate thread(s) that are still running when your app quits. You'll have to check with the docs or anything else you can find on this library and see if it needs you to do anything special to shut it down before your app closes.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
This is usually caused by an improper shutdown of a component in your app. Most likely, this would be the .DLL you're using. It's possible that it created a seperate thread(s) that are still running when your app quits. You'll have to check with the docs or anything else you can find on this library and see if it needs you to do anything special to shut it down before your app closes.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Thanks for the reply, but when you want purposely close the application, is it the VB application responsible for that or the dll application which is written in C++ and has many threads? Thanks
Yes! Any .DLL you load becomes a part of your code, not a seperate process. This is a curious question, because throughout all coding, if your code creates or loads something, your code is also responsible for managing and destroying that something properly. Making the assumption that an object or runtime can clean itself up without you telling it to do so is a very bad thing to do. This practice leads to unstable applications and operating systems. For instance, if you application creates a Graphics object, you are also responsible for destroying it when your done with it. If not, you'll eventually run the system out of resources and crash the whole operating system.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007