473,775 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does the for closing event always fire?

Hi All

VS 2008 Pro

It appears that the form_closing event of a form may not always fire. I put
an explicit lock on a customer record when it is open for edit and then
remove the lock in the form_closing event when the form is closed. This used
to work fine in VB6 but appears to be a bit unreliable in VB.Net.

code------------------------------------------------------------------

Private Sub frmAccount_Form Closing(ByVal sender As Object, ByVal e As
System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
Select Case Ask_Save(oAccou nt.IsDirty)

Case Windows.Forms.D ialogResult.Can cel

e.Cancel = True

Return

Case Windows.Forms.D ialogResult.No

oAccount.Fetch( ) 'refresh the data

Case Windows.Forms.D ialogResult.Yes

oAccount.Operat or_ID = Glo.OperatorID

_DataChanged = oAccount.Save()

End Select

'--------------------

'clear user form lock

'--------------------

ClearLock(oLock )

End Sub

Can anyone offer any suggestions on how to overcome this. Should I use the
form_disposed event or perhaps the Finalise method?

Thank you for any input

Harry
Jun 27 '08 #1
6 2542
"Harry" <ha*********@ff apaysmart.com.a uschrieb
Hi All

VS 2008 Pro

It appears that the form_closing event of a form may not always
fire. I put an explicit lock on a customer record when it is open
for edit and then remove the lock in the form_closing event when the
form is closed. This used to work fine in VB6 but appears to be a
bit unreliable in VB.Net.

[...]
Can anyone offer any suggestions on how to overcome this. Should I
use the form_disposed event or perhaps the Finalise method?
No, the Form_Closing event is the right place. Have you set a breakpoint
in the event handler? Is it reached every time? I have never seen a Form
closing without the FormClosing event fires.
Armin

Jun 27 '08 #2
Never seen that. You may want to check that the event is triggered. My guess
would be rather than oAccount.IsDirt y is not correct perhaps making the
dialog auto-answering (not sure what you have done in Ask_Save, does it
always show a UI or can it return directly ?) ?

--
Patrice

"Harry" <ha*********@ff apaysmart.com.a ua écrit dans le message de groupe
de discussion : es************* *@TK2MSFTNGP03. phx.gbl...
Hi All

VS 2008 Pro

It appears that the form_closing event of a form may not always fire. I
put an explicit lock on a customer record when it is open for edit and
then remove the lock in the form_closing event when the form is closed.
This used to work fine in VB6 but appears to be a bit unreliable in
VB.Net.

code------------------------------------------------------------------

Private Sub frmAccount_Form Closing(ByVal sender As Object, ByVal e As
System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
Select Case Ask_Save(oAccou nt.IsDirty)

Case Windows.Forms.D ialogResult.Can cel

e.Cancel = True

Return

Case Windows.Forms.D ialogResult.No

oAccount.Fetch( ) 'refresh the data

Case Windows.Forms.D ialogResult.Yes

oAccount.Operat or_ID = Glo.OperatorID

_DataChanged = oAccount.Save()

End Select

'--------------------

'clear user form lock

'--------------------

ClearLock(oLock )

End Sub

Can anyone offer any suggestions on how to overcome this. Should I use the
form_disposed event or perhaps the Finalise method?

Thank you for any input

Harry
Jun 27 '08 #3
Armin,
>
No, the Form_Closing event is the right place. Have you set a breakpoint
in the event handler? Is it reached every time? I have never seen a Form
closing without the FormClosing event fires.
Me either, however as you set somewhere "End" in a program what is than the
effect.

Cor
Jun 27 '08 #4
"Cor Ligthert [MVP]" <no************ @planet.nlschri eb
Armin,

No, the Form_Closing event is the right place. Have you set a
breakpoint in the event handler? Is it reached every time? I have
never seen a Form closing without the FormClosing event fires.
Me either, however as you set somewhere "End" in a program what is
than the effect.
I use "End" very frequently...
....followed by "Sub", "Function", ...

;-)

Armin
Jun 27 '08 #5
On Tue, 29 Apr 2008 08:09:53 +1000, "Harry"
<ha*********@ff apaysmart.com.a uwrote:
>Hi All
---snip---
>Can anyone offer any suggestions on how to overcome this. Should I use the
form_dispose d event or perhaps the Finalise method?
You are not crazy. There are situations where the FormClosing event
does not fire.

There is a discussion about it here with a few examples:
http://forums.devshed.com/net-develo...-c-475778.html

For my own part, I have on occasion been bitten by one of those:
---snip---
"FormClosin g will not fire on a form if it is a secondary form that is
not owned by the primary form, and the primary form is closed, causing
Main() to return and the application to exit."
---snip---

In any case, you should *not* use Disposed or Finalize to control
your locks.

/Joergen Bech

Jun 27 '08 #6
"Joergen Bech" <jb***@post1.te le.dkschrieb
---snip---
"FormClosin g will not fire on a form if it is a secondary form that
is not owned by the primary form, and the primary form is closed,
causing Main() to return and the application to exit."
---snip---
Good point. However, IMO it's the programmers fault if he sets Form1 as
the startup object on the one hand, and also wants to keep Form2 alive
even if Form1 has been closed on the other hand. That's a
contradiction. - unless the "applicatio n framework" is used and the
shutdown mode is "when last form closes".
Armin

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2261
by: Ron L | last post by:
I have an MDI application with a number of child windows. In each child window I am catching the Closing event and having the child window decide if it should set cancel to true. The intent here is to ensure that no child window can close while it is in a state where user entered information can be lost. I have just noticed that while the Closing event is caught if I click the X on the child window, it is not caught if I click the X on...
1
2204
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
1
2597
by: Duwayne | last post by:
I am having a lot of trouble with an ascx page that has a textbox that *should fire a textchange event when the text changes. The main aspx page dynamically loads the ascx page and has a image button that initiates the submit. during submit, 2 events *should fire, 1 from the textbox and 1 from the image button. The image button event always fire but the textbox textchange event does not. Anyone has any ideas? Notes: During postback, I...
5
4489
by: Uma Muthu | last post by:
Hello Everyone, How can I capture the event of closing the IE browser from within an ASP.NET web application? TIA, Uma
11
2827
by: OldProgrammer | last post by:
All the documentation and discussion I have read indicate that the Session_End is not supposed to fire unless you are in "inProc" Session state mode, and then only on Session Timeout or at Session Abandon. I need the event to fire at Session timeout in order to capture and store the Datetime this occurs. However in the application I am writing, I have been unable discern any indication that the event is firing. I have used break...
22
8835
by: Charles Law | last post by:
Could someone please explain to me, in words of one syllable or less, how I get the Validating event to fire for a form. I have a form with one text box, and two buttons: OK and Cancel. I have the OK button set as the AcceptButton and the Cancel button as the .... well, you've guessed it. I click OK and the form closes, without going to the Form1_Validating event. I could validate in the Click event of the OK button, but I can't...
1
1968
by: Pushpadant Kacha via .NET 247 | last post by:
hi, I have an application where i am using a textbox and a submitbutton. the autopostback property of the textbox is set to true. now if there is a change in the textbox then thetexbox_changetext event is fired(provided it has lost focus) butif the textbox is changed and before losing the focus if thesubmit button is clicked...only the textbox_change event isfired but SUBMIT Button EVENT is NOT fired....i dont know how tohandle both the...
1
1415
by: Marius Groenendijk | last post by:
Dear Group, I have a MDI with children which may be editing data. If a MDI child closes its Closing handler asks a question 'exit w/out saving?'. On closing the MDI its pops a question 'Exit app?'. If the MDI closes *first* the questions asked by the MDI children appear and *then* the question by the MDI. This is because the closing events in the MDI children get fired *first* while Closing the MDI.
3
2215
by: mtczx232 | last post by:
I have TabControls that Hold Forms on his TabPges (this make me easy to give ability to Designing each form in his IDE window). When form x is in middle of Edit Data Mode, I going to prevent: Closing App or switch to other tabs until save done explicit by user. So I try use events like: deactivate,leave,lostfocus,formclosing,validating to prevent user leave before save. but no one work: the not fire at all when app closing or switch...
0
9625
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9920
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8944
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6721
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5489
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4024
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.