Does the for closing event always fire?

H

Harry

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
 
A

Armin Zingler

Harry said:
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
 
C

Cor Ligthert [MVP]

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
 
A

Armin Zingler

Cor Ligthert said:
Armin,

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
 
A

Armin Zingler

Joergen Bech said:
---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
 
H

Harry

Joergen Bech said:
Suppose we have a main form (mdi container) that can display
multiple order lists, each in their own mdi child window.

Suppose we launch non-mdi client, modeless order detail windows
by double-clicking records in those order lists.

Now, we close the main form.

I do not know if this is one of the scenarios. There is also the
issue of how forms are related to each other, i.e. by setting the
Owner property.

I do not remember what my own problem was - only that I
cleaned up the messaging system so I did not depend on those
events.

I try to use delegates in such situations. Usually I use a
broadcasting
system, where the subscribers can tell by a "source" property whether
they initiated the broadcast or whether they should reflect a new
state.
...
An entirely different matter is the use of pessimistic locking vs.
optimistic locking in the original poster's program: What happens
if a record is locked and the program crashes or there is a power
failure? Is ClearLock then ever called or how would that record be
freed for write-access to other users?

/Joergen Bech
Thanks for your advice. The problems with clearing locks are all handled
properly. We have had this type of system in place for some 10 years with 40
users and have only ever had to use the administrator "Clear All Locks"
twice. As stated, I have never seen this problem until .Net.

Anyway, thanks to all for your excellent help. I have put in place some code
to check if the form_loading event does not fire.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top