Closed 6DiegoDiego9 closed 1 year ago
Hi @6DiegoDiego9 ,
Thank you for the kind words and for your feedback!
Demo3
on all of my machines and it does not crash. I tested on both Windows and Mac on both x32 and x64. I am definitely curious as to why it crashes on your machine. Have you done any changes to the code or did you just ran it as downloaded?I tested again with your fresh new demo file and this time it works! I'm not 100% sure I didn't touched it then. Thanks for pushing me to try it again! :)
I remain very much interested in this point. I hope for some good news in future :)
Thanks again!
Hi @6DiegoDiego9 ,
However, I am sad to say that while debugging or while code is running (which includes a DoEvents
loop), if state is lost then indeed the callbacks are not called, If a form is displayed, then the callbacks still work (unless a DoEvents
loop is run from within the form or state is lost while some other code is running).
So, there are 2 cases where this fails:
DoEvents
loop or something else running that causes the state loss. If no DoEvents
calls are made then the only code, that I know of, than can cause a state loss is to call End
while running code. This should not be an issue in production as End
is never used alone in production - please correct me here if I am wrong and if you are aware of other cases. So, this leaves us with a DoEvents
loop which I never use but I do admit this may affect how others use this repo - unfortunately I do not have a solution for this and I don't think there is any way to go around this.Any advice or criticism is always welcome, so please do help if you have any ideas on how to improve this or any other of my repos.
Thank you again for your feedback!
With Kind Regards, Cristian
Hi @cristianbuse
The first reason why I'm interested in a state loss callback is in VBA apps that open or modify external resources, to call a procedure that cleans them on crash. My most important use would be to improve SeleniumVBA by adding a cleaner procedure triggered on crash, that (maybe optionally with a Yes/No) closes the webdriver.exe and browser opened by the script session, as current version is unable to reuse a browser used in a previous script session and anyway we often want to run/test scripts on fresh new browser sessions.
Scenario 1: while I'm building a VBA script to scrape/interact with a website, adding commands locating html elements, occasionally an error is raised (eg. the given xpath doesn't find an element) and I need to VBE "Reset" and run the whole script again to see if everything works until to my last fixed line of code. I'd like VBA-StateLossCallback to close the exe+browser on "Reset".
Scenario 2: my script is scheduled to scape data from a website, daily, until a day the website changes the html of an element and my script raises the error. The user (or me) press "End" to terminate. I'd like VBA-StateLossCallback to close the exe+browser on "End".
As far as I understand, the current VBA-StateLossCallback isn't able to detect these two kind of state losses. Is it correct?
Hi @6DiegoDiego9 ,
As far as I understand, the current VBA-StateLossCallback isn't able to detect these two kind of state losses. Is it correct?
Correct. The reason is that the IUnknown::Release
is not called anymore if Reset/End is pressed while code is running. This is somenthing I was not aware until you raised this issue. It's simply how VB works behind the scenes and there's absolutely nothing I can do about it. In a few weeks time I will try to investigate other ways of achieving this but not Release
. If I find anything interesting then I will surely write you here.
Hi Cristian First of all thanks for this class! it seems a little gem!
However on my first try I had the following problems: 1) your Demo3 (
slc.InitByAddress AddressOf TestX, "Testing"
) crashes my Excel application just after writing "State was lost. Clean proc X testing" on the console 2) Demo1 and Demo2 seems to work if I fully execute them and press Reset afterward. But if I make a state loss by other means, for example: by pressing Reset while in debugging mode or by pressing Reset while in a loop of doEvents or by adding a "Dim foobar as object" while in debugging mode (causing a state loss) ... it doesn't call the given macro.