[...]
I'm using microsoft's COM object for running VB scripts:
MSScriptControl.ScriptControlClass. I have a method in my managed
code, which is running in a dedicated worker thread which calls the
"Run()" method of this COM object. now, I want to give the user the
option of pausing the execution of the script and then, of course,
resuming it. this MSScriptControl.ScriptControlClass object doesn't
have a built in "pause" method. I thought I can externally pause the
script by pausing the worker thread running the wrapper method. Any
idea on who to acheive the result without using Thread.Suspend()?
IMHO, to do this correctly you will need to essentially write a VBScript
debugger. That is, some component that knows enough about VBScript to
control its execution statement by statement, and which has an opportunity
between each statement to interrupt execution of the script.
There are lots of things that can go wrong if you just suspend a thread
arbitrarily. I would _hope_ those risks may be reduced if all that thread
is doing is executing a VBScript (on the assumption that a VBScript is
limited in what it could actually be doing), but even there I think there
are potential problems.
And of course, Willy's caveat about an OS thread versus a managed thread
is appropriate as well: if you're some unmanaged component, the thread may
or may not be executing in a context where a managed Thread.Suspend() call
will work. At the very least, you may have to use p/invoke to get at the
real thread and suspend/resume it.
Of course, this begs the question: if you're not already writing a
VBScript debugger (and it sounds like you aren't), why does the user need
the ability to suspend and resume the operation of VBScript code?
Modification of the flow of any executable code is not something to be
taken lightly, IMHO. It's not the sort of thing that you just stick in a
"suspend" button and a "resume" button, hook it to a few lines of code,
and let the user have a party with.
Pete