|
-
Apr 29th, 2026, 11:29 AM
#1
Thread Starter
New Member
formclosing, formclosed and applicaton events not firing when app close
I'm going crazy. When I close my winforms app, by closing the start form, formclosing, formclosed or applicationevents are not executed.
Something is messing with my code so that it is skipped.
I have telerik version 2016 installed.
I have VS2022 or VS2026, .NET framework 4.8 (it is about to be an older app)
Anyone have an idea what could be wrong, or if there is another way to tell that you are about to exit the windows app?
-
Apr 30th, 2026, 08:23 AM
#2
Re: formclosing, formclosed and applicaton events not firing when app close
Are you closing the form programmatically or is the user simply clicking the close icon?
If it's the former, could you show the code that you're using?
-
Apr 30th, 2026, 08:36 AM
#3
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
Im just click the close icon in the upper right corner of the form
-
Apr 30th, 2026, 08:46 AM
#4
Re: formclosing, formclosed and applicaton events not firing when app close
Hmm, ok.
What are you doing to check if they're executing or not? For example, is it that you're setting up a breakpoint in the events and it's simply not breaking or are you doing something else?
-
Apr 30th, 2026, 11:29 AM
#5
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
Stop command, msgbox, some kind of code, nothing work.
-
Apr 30th, 2026, 01:23 PM
#6
Re: formclosing, formclosed and applicaton events not firing when app close
At this point, I'm inclined to believe that the event is not attached properly. This typically happens if you copy/paste forms, but it is a bit unusual to see happen to the application events.
Could you copy/paste the method signature of the various points that should be firing, but aren't?
-
Apr 30th, 2026, 07:27 PM
#7
Re: formclosing, formclosed and applicaton events not firing when app close
 Originally Posted by dday9
At this point, I'm inclined to believe that the event is not attached properly. This typically happens if you copy/paste forms, but it is a bit unusual to see happen to the application events.
Could you copy/paste the method signature of the various points that should be firing, but aren't?
Yeah, it does sound like the Handles clause could be missing from the event. Actually seeing the event code would make things a lot clearer.
-
May 1st, 2026, 12:50 AM
#8
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
Do you mean application events? When i opened it, it was actually empty, so i copy the events in. The app start event is actually working, but not the rest.
-
May 1st, 2026, 02:24 AM
#9
Re: formclosing, formclosed and applicaton events not firing when app close
Post the form closing event code.
-
May 1st, 2026, 04:01 AM
#10
Re: formclosing, formclosed and applicaton events not firing when app close
FormClosing and FormClosed are events you can handle in your Form, as Form1_Click is an event you can handle in your Form.
See this… https://learn.microsoft.com/en-us/do...-windows-forms
These are part of your Form1 code, NOT part of application events…
Last edited by .paul.; May 1st, 2026 at 04:28 AM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 1st, 2026, 05:11 AM
#11
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
I know,.and as i wrote, its doesnt work.
-
May 1st, 2026, 05:21 AM
#12
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
 Originally Posted by wes4dbt
Post the form closing event code.
Code:
Private Sub MDImain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
MsgBox ("Stop") DONT WORK
'Stop DONT WORK
Select Case e.CloseReason
Case CloseReason.ApplicationExitCall
' This is the result of Application.Exit()
e.Cancel = False
Case CloseReason.UserClosing
' This is the result of clicking the red X
Select Case MessageBox.Show("Are you sure you wish to exit?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Case DialogResult.Yes
e.Cancel = False
Case DialogResult.No
e.Cancel = True
End Select
Case Else
e.Cancel = False
End Select
If Not e.Cancel Then
End If
ALSO DONT WORK
BY THE WAY, HERE IS MY APPLICATONEVENTS KODE:
Code:
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
'AddHandler(SystemEvents.SessionEnding, AddressOf ShutDown.OnShuttingDown)
'AddHandler(SystemEvents.SessionEnded, AddressOf ShutDown.OnShutDown)
' Denne klasse håndterer globale applikationshændelser
Partial Friend Class MyApplication
Public Event ApplicationExit(sender As Object, e As EventArgs)
' Kører når applikationen starter
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
'MsgBox("Programmet starter op.")
'My.Application.Log.WriteEntry("Application started at " & My.Computer.Clock.GmtTime.ToString)
End Sub
' Kører når applikationen er ved at lukke
'Private Sub MyApplication_Shutdown(sender As Object, e As EventArgs) Handles Me.Shutdown
' 'Process.Start("c:\test 01\Installationsvejledning.pdf") ' Eksempel på at starte en proces ved nedlukning
' 'MsgBox("Programmet lukker ned.")
'End Sub
Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
MsgBox("Pro")
End Sub
' Kører når en ubehandlet fejl opstår
Private Sub MyApplication_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs) Handles Me.UnhandledException
'Debug.WriteLine("Der opstod en ubehandlet fejl: " & e.Exception.Message)
' Hvis du vil forhindre at programmet lukker:
' e.ExitApplication = False
End Sub
' Kører når applikationen afsluttes (ApplicationExit)
Private Sub MyApplication_ApplicationExit(sender As Object, e As EventArgs) Handles Me.ApplicationExit
'Stop
'Process.Start("c:\test 01\Installationsvejledning.pdf")
MsgBox("ApplicationExit: Hele applikationen lukker ned.")
End Sub
End Class
End Namespace
In application event, 'MyApplication_Startup' actually works, not the rest.
End Sub
Last edited by dday9; May 1st, 2026 at 09:13 AM.
Reason: Added code tags
-
May 1st, 2026, 06:42 AM
#13
Re: formclosing, formclosed and applicaton events not firing when app close
This might help...
 Originally Posted by learn.microsoft
If the form is a multiple-document interface (MDI) parent form, the FormClosing events of all MDI child forms are raised before the MDI parent form's FormClosing event is raised. Likewise, the FormClosed events of all MDI child forms are raised before the FormClosed event of the MDI parent form is raised. Canceling the FormClosing event of an MDI child form does not prevent the FormClosing event of the MDI parent form from being raised. However, canceling the event will set to true the Cancel property of the FormClosingEventArgs class that is passed as a parameter to the parent form. To force all MDI parent and child forms to close, set the Cancel property to false in the MDI parent form.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 5th, 2026, 11:57 AM
#14
Re: formclosing, formclosed and applicaton events not firing when app close
@PeerDK
Did that help? Is your issue resolved now? Don’t forget to mark your thread RESOLVED
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 6th, 2026, 07:52 AM
#15
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
I still can't get it to work. Not even from mdichilds, the formclosing and formclosed events aren't caught either.
Does anyone have any good ideas? There must be something in my code that's making it not work.
-
May 6th, 2026, 08:32 AM
#16
Re: formclosing, formclosed and applicaton events not firing when app close
Something is happening, but at this point you need to go back to basic debugging techniques.
What I would do is bring your code down to the most minimal possible solution, e.g.
Code:
Private Sub MDImain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
End Sub
Then, slowly add code back, e.g.
Code:
Private Sub MDImain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
MessageBox.Show("MDImain_FormClosing")
e.Cancel = True
End Sub
Then:
Code:
Private Sub MDImain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
MessageBox.Show("MDImain_FormClosing")
e.Cancel = (e.CloseReason <> CloseReason.ApplicationExitCall)
End Sub
Then:
Code:
Private Sub MDImain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
MessageBox.Show("MDImain_FormClosing")
Select Case e.CloseReason
Case CloseReason.ApplicationExitCall
e.Cancel = False
Case CloseReason.UserClosing
e.Cancel = (MessageBox.Show("Are you sure you wish to exit?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) <> DialogResult.Yes)
End Select
End Sub
... and so on, until your code looks like it does in its current state.
If at any point the code stops behaving like you expect it to, then you've found where your bug is.
-
May 6th, 2026, 10:24 AM
#17
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
I have already tried that. The sub is never activated.
-
May 6th, 2026, 11:37 AM
#18
Re: formclosing, formclosed and applicaton events not firing when app close
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 6th, 2026, 01:10 PM
#19
Re: formclosing, formclosed and applicaton events not firing when app close
 Originally Posted by PeerDk
I have already tried that. The sub is never activated.
I'm going to rephrase what I was originally going to respond with.
What are you expecting to happen? I think there may be some confusion because, for example, one would never see this message box appear because the application is shutting down:
Code:
Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
MsgBox("Pro")
End Sub
-
May 13th, 2026, 08:52 AM
#20
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
I got tired of not being able to find the error, so I made a button with the code Application.exit. Then form.closing and form.closed suddenly work.
I simply don't understand why form.closing doesn't work when I press the red cross in the form, so the program closes.
-
May 13th, 2026, 11:49 AM
#21
Re: formclosing, formclosed and applicaton events not firing when app close
What i posted in post #18... Clicking X's works for me
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 14th, 2026, 01:30 AM
#22
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
 Originally Posted by .paul.
What i posted in post #18... Clicking X's works for me
But it dont work when i Click x, thats the whole problem, as i explained in my first post. Form.closing does NOT work when closing the program normally, but apparently does when I use the code application.exit in a button I make.
-
May 14th, 2026, 07:25 AM
#23
Re: formclosing, formclosed and applicaton events not firing when app close
 Originally Posted by PeerDk
I got tired of not being able to find the error, so I made a button with the code Application.exit. Then form.closing and form.closed suddenly work.
I simply don't understand why form.closing doesn't work when I press the red cross in the form, so the program closes.
What red cross are you pressing?
Are any exceptions being thrown?
-
May 14th, 2026, 09:38 AM
#24
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
 Originally Posted by PlausiblyDamp
What red cross are you pressing?
Are any exceptions being thrown?
Upper right corner, close form. Nothing at all happen in form.closing and form.closed also nothing in application events.
-
May 14th, 2026, 12:06 PM
#25
Re: formclosing, formclosed and applicaton events not firing when app close
 Originally Posted by PeerDk
Upper right corner, close form. Nothing at all happen in form.closing and form.closed also nothing in application events.
When you have an MDI Form, clicking the X in a child Form doesn't raise the parent .Closing and .Closed events. Each Form has its own events...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 14th, 2026, 09:28 PM
#26
Re: formclosing, formclosed and applicaton events not firing when app close
The order of events raised due to clicking the X are:
(Clicking the X) In a child Form (also a regular Form), first the Form’s FormClosing event, then assuming you didn’t set Cancel, the Form’s FormClosed event.
(Clicking the X) In an MDIForm, first the MDIForm’s FormClosing event, then assuming not cancelled, the FormClosing followed by FormClosed events of each child Form, finishing with the MDIForm’s FormClosed event.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2026, 02:09 AM
#27
Thread Starter
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
 Originally Posted by .paul.
The order of events raised due to clicking the X are:
(Clicking the X) In a child Form (also a regular Form), first the Form’s FormClosing event, then assuming you didn’t set Cancel, the Form’s FormClosed event.
(Clicking the X) In an MDIForm, first the MDIForm’s FormClosing event, then assuming not cancelled, the FormClosing followed by FormClosed events of each child Form, finishing with the MDIForm’s FormClosed event.
I know, but nothing happens.
-
May 15th, 2026, 02:38 AM
#28
Re: formclosing, formclosed and applicaton events not firing when app close
Well there are two alternatives in that case...
Option 1. Create a new application, adding your previous app code to the new app, incrementally block by block, running and testing after each new addition. Find the code that breaks it, and we can probably help. (with your code in the My Namespace, AddHandler outside of a Class wouldn't work, and i've never seen much code used in Class MyApplication - I wouldn't recommend that.)
Option 2. This option depends how huge your app is, and how private it is. I could have a look at it if you upload it somewhere.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 15th, 2026, 01:07 PM
#29
Re: formclosing, formclosed and applicaton events not firing when app close
There is also the possibility that the forms designer code is corrupted.
Option 1 above would solve that but if it's a large app you might try just creating a new form.
-
May 22nd, 2026, 01:46 AM
#30
New Member
Re: formclosing, formclosed and applicaton events not firing when app close
problem maybe your case statements not firing or the Closing sub is overridden by another one
use this Protected Overrides Sub OnClosing(ByVal e As CancelEventArgs)
in onClosing sub
add only -------------------- e.Cancel = true
if stop closing, work on the case statements
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|