473,395 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Select Case Ask_Save(oAccount.IsDirty)

Case Windows.Forms.DialogResult.Cancel

e.Cancel = True

Return

Case Windows.Forms.DialogResult.No

oAccount.Fetch() 'refresh the data

Case Windows.Forms.DialogResult.Yes

oAccount.Operator_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 2518
"Harry" <ha*********@ffapaysmart.com.auschrieb
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.IsDirty 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*********@ffapaysmart.com.aua é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_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Select Case Ask_Save(oAccount.IsDirty)

Case Windows.Forms.DialogResult.Cancel

e.Cancel = True

Return

Case Windows.Forms.DialogResult.No

oAccount.Fetch() 'refresh the data

Case Windows.Forms.DialogResult.Yes

oAccount.Operator_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.nlschrieb
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*********@ffapaysmart.com.auwrote:
>Hi All
---snip---
>Can anyone offer any suggestions on how to overcome this. Should I use the
form_disposed 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---
"FormClosing 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.tele.dkschrieb
---snip---
"FormClosing 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 "application 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
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...
1
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
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...
5
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
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...
22
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...
1
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...
1
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...
3
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:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.