Ensure code runs at end of method (COM.IDispatch bug)

I have an app that acts as a server. It needs to be responsive all the time.

In a timer I have and action event that works like this:

[code]If Updating Or AppQuit Or PauseTimers Then Return 'make the updates wait on their turn
Updating = True

If Condition1 then
'do some stuff
Updating = False
End If

If Condition2 then
'do some stuff
Updating = False
End If

'do some updating stuff, call methods etc…

Updating = false

I have this problem that the app gets ‘stuck’ with Updating = true yet the action event isn’t stuck in a loop because the app remains responsive otherwise.

I tried adding this code at the bottom to ensure that the Updating flag is return to false yet the problem still shows up occasionally.

Exception err Updating = False Raise err

Where am I going wrong.

  1. I already checked, and there are only two returns. Both of those are proceeded by Updating = False
  2. I search and the Update flag is not being set anywhere else in the app. In fact Updating = True is found only once in the entire app.

Ok pinpointed it to some where in this block.

[code]Debuginfo = “10”

'check update flags for getting list data from QuickBooks
if UpdateList.Ubound > -1 Then
dim u as String = UpdateList(0)
UpdateHandler u
End If
Debuginfo = “11”[/code]

Here is the line that causes the problem:

If Not connectEvents Then Return

Here is the call stack leading up to the problem, starting in the timer action event

Timer.Action 'event UpdateHandler 'method in same window as timer qb.GetPriceLevels 'method in qb module qb.connect 'method in qb module qbfc13lib.QBSessionManager.constructer 'invoked like this: Session = New qbfc13lib.QBSessionManager 'This is a class in an Inserted ActiveX Component
in the class’s constructor method the following statement returns not from the constructor as it should but it returns from the timer.action event as well.

If Not connectEvents Then Return

Actually setting Session = nil is where the problem is. Creating the new session was actually causing the old session to be destroyed.
This is the code in the destructor.

If ObjectMap <> Nil And ObjectMap.HasKey(Handle) Then ObjectMap.Remove(Handle)

It seems like prior versions of Xojo (2015r3) the app crashed when this problem came up. In Xojo 2017r2 the app doesn’t crash but other undesirable behavior occurs. I built a solution for restarting the app after the crash. It’s a bit more difficult to handle this situation because instead of crashing it seems to clear the call stack and ‘start over’. Arg… After almost 4 hours of unfruitful testing I’m back to 2015r3.

Here is a short video showing the problem. Hopefully Xojo can figure it out. <https://xojo.com/issue/49572>