Pergunta

I am trying to catch when Microsoft Windows Task Manager is closing the application. I know there are these UnloadMode possibilities: '0 The user has chosen the Close command from the Control-menu box on the form. '1 The Unload method has been invoked from code. '2 The current Windows-environment session is ending. '3 The Microsoft Windows Task Manager is closing the application. '4 An MDI child form is closing because the MDI form is closing.

Code:

Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'[do saving]
End Sub

But it does nothing when I close application using task manager. If I close using Close button - it saves all what I need. Where is the problem?

Foi útil?

Solução

If you terminate via the processes tab in task manager no further code gets executed whereas if you terminate via the applications tab it does.

See this answer on another forum:

By user "vbface" (2003-12-29) :

Killing a process in the Task Manager immediately (or so) kills the program where it is, with no further events firing. It is like putting an END statement in VB. No cleanup, no closing processes, just a termination of the app.

http://www.xtremevbtalk.com/showthread.php?t=131604

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top