You are here: PSPad forum > English discussion forum > Error when closing PSPad while a VBScript loop is running

Error when closing PSPad while a VBScript loop is running

Goto Page: 1 2 Next

#1 Error when closing PSPad while a VBScript loop is running

Posted by: Professor Bernd | Date: 2020-05-18 07:14 | IP: IP Logged

If you quit PSPad while a VBScript loop is running, an error message appears every time. Can you please fix it?

image

VBScript Example

' TestLoop.vbs
const module_name = "TestLoop" 'this name must be unique !!!
const module_ver = "0.001" 'version

sub MyTestLoop()
Do
Sleep(100)
Loop
end sub

' name "Init" is required, its called automatically during initialization to create menu items
sub Init
MyTestLoop()
end sub

Options: Reply | Quote | Up ^


#2 Re: Error when closing PSPad while a VBScript loop is running

Posted by: pspad | Date: 2020-05-18 07:33 | IP: IP Logged

I tested it with current 5.0.4 x32 and no error occured

P.S. sorry. Debug version was OK, cause it's slover. Release version causes this error.
I call script end by force when PSpad is closing, but this is caused by delay in the script in my opinion.
I don't know if I will be able to handle it, script runs in separate space, everything is joined via interfaces with callbacks.

Edited 1 time(s). Last edit at 2020-05-18 07:43 by pspad.

Options: Reply | Quote | Up ^


#3 Re: Error when closing PSPad while a VBScript loop is running

Posted by: pspad | Date: 2020-05-18 08:15 | IP: IP Logged

I found, i am able to handle it.
But this way how to use scripts is wrong. In your case PSPad never finish script inicialization and it's (at least scripts) behavior can be undetermined.

Anyway, the message won't be shown on exit

Options: Reply | Quote | Up ^


#4 Re: Error when closing PSPad while a VBScript loop is running

Posted by: Professor Bernd | Date: 2020-05-18 08:31 | IP: IP Logged

You mean my example script? If so, that was really just an example. In my real script, loops are called by shortcut, but never in the init.

pspad:
Anyway, the message won't be shown on exit

Did you fix the bug? Can I use loops that are called by shortcut and still run when PSPad is closed?

Options: Reply | Quote | Up ^


#5 Re: Error when closing PSPad while a VBScript loop is running

Posted by: vbr | Date: 2020-05-18 13:52 | IP: IP Logged

pspad:
I found, i am able to handle it.
But this way how to use scripts is wrong. In your case PSPad never finish script inicialization and it's (at least scripts) behavior can be undetermined.

Anyway, the message won't be shown on exit

Hi,
I believe, I had some similar problem when I was experimenting with GUIs for scripts some years ago, probably the event loop of these script windows outside of PSPad caused similar problems on closing of PSPad or reloading scripts cf:
forum.pspad.com (Czech forum).

It seems to me, that some kind of cleanup function "exit" or "onBeforePSPadExit...", "onBeforeScriptRecompile..." as a kind of complement to Init() might help in this context; however, I don't know, if it can be implemented for WSH.
I imagine, if such function were defined in the script (it should be only optional), some kind of "exit" message could be sent to it and the cleanup code could be run within the script - such as destroying the GUI window, possibly some other "external" connections etc.
It is likely, that this would require some waiting until exit() completes or some timeouts; closing the program can be a bit slower in such cases (like the script init is currently), but it could be taken as the responsibility of the script writer; probably the (most?) "hangs" in such cases can be handled this way (except for errors not handled in the script itself) .

Thanks and regards,
vbr

Edited 1 time(s). Last edit at 2020-05-18 13:55 by vbr.

Options: Reply | Quote | Up ^


#6 Re: Error when closing PSPad while a VBScript loop is running

Posted by: pspad | Date: 2020-05-18 14:15 | IP: IP Logged

When PSPad is to close, I go through all script engines and call terminate for all running scripts.
But in this case, this script loop was call in init scripting engine phase - this occures one time when PSpad starts. And cause this loop in init phase, INIT never finished.
The exception was correct - PSPad stops scripts by force and script raised exception.
WHat I did was that exception isn't shown in the closing phase.

Options: Reply | Quote | Up ^


#7 Re: Error when closing PSPad while a VBScript loop is running

Posted by: vbr | Date: 2020-05-18 16:01 | IP: IP Logged

pspad:
When PSPad is to close, I go through all script engines and call terminate for all running scripts.
But in this case, this script loop was call in init scripting engine phase - this occures one time when PSpad starts. And cause this loop in init phase, INIT never finished.
The exception was correct - PSPad stops scripts by force and script raised exception.
WHat I did was that exception isn't shown in the closing phase.

Thanks for the clarification,
could it be possible, that the script maybe gets a chance to react to such closing message, e.g. by calling such optional function, where the closing of script ressources, objects can etc. be handled before the program termination?

Thanks and regards,
vbr

Options: Reply | Quote | Up ^


#8 Re: Error when closing PSPad while a VBScript loop is running

Posted by: pspad | Date: 2020-05-18 16:26 | IP: IP Logged

Possible is nrar anything, but callbacks in interfaces are not easybto do. Intetfaces are too abstract.
For callback you need to know id of process (running scriptsl

I can do general function what will return states, e.g. PSPad is closing. But script must react it snd I am afraid PSPad will terminate script faster than script reaction.
We can extend scripts of flags, that PSPad will wait till script ends.

There is lot of possibilities what can be done. The question is if it worth the effort and time you must put into it.

Options: Reply | Quote | Up ^


#9 Re: Error when closing PSPad while a VBScript loop is running

Posted by: vbr | Date: 2020-05-18 18:33 | IP: IP Logged

pspad:
Possible is nrar anything, but callbacks in interfaces are not easybto do. Intetfaces are too abstract.
For callback you need to know id of process (running scriptsl

I can do general function what will return states, e.g. PSPad is closing. But script must react it snd I am afraid PSPad will terminate script faster than script reaction.
We can extend scripts of flags, that PSPad will wait till script ends.

There is lot of possibilities what can be done. The question is if it worth the effort and time you must put into it.

Thanks for the detailed explanation, I clearly haven't seen the technical problems. These options probably won't help in the mentioned contexts, where a kind of loop is run in parallel to PSPad - be it GUI or some other independent code.

My idea was likely too simple and possibly unusable for the underlying mechanism. I imagined a one-time function call of such hypothetical function "exit", just like Init() but before closing the program (or reloading scripts). If the script would define this function, it would be executed at that moment (with some waiting for completing), otherwise the program could close and terminate the scripts just like now.
But anyway, I can understand, that I am likely missing some technical implications and details, which make this difficult.

Thanks,
vbr

Options: Reply | Quote | Up ^


#10 Re: Error when closing PSPad while a VBScript loop is running

Posted by: pspad | Date: 2020-05-18 18:38 | IP: IP Logged

It can be general function, returning if script should end and test this function in loops. If function return true, script should end.

But again, PSPad can terminate script faster then the function will be handled by script in case script do some time consuming job.

Options: Reply | Quote | Up ^


Goto Page: 1 2 Next





Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR