VBscript call windown main event loop - asynchronous

Running a QTP script that has a loop with a 100 ms wait inside. When trying to hit the stop button while in this loop, the script does not stop, so it hangs until the loop is exited.I guess the 100ms is to fast for QTP to call the main event loop and process the button click, but I don't want to slow down the loop.
Is it possible to manually call the windows main event loop so the button click is processed, or is there a better way to get this to work?
Thanks in advance,
Kregg

The following code can indeed be aborted by pushing the "Stop" button in 11.00.0.0 build 1018:
do
Wait 0,100
loop
Or did I get you wrong?

Related

How to realize a prompt dialog box when load a large file or other things using Qt?

I need to load a large file to parse and draw with OpenGL. The whole process is very time-consuming. So I want to realize a prompt dialog box before parse. But the code as following is not work.
void parseFile()
{
QMessageBox* msgbox = new QMessageBox();
msgbox->setModal(false);
msgbox->setWindowTitle(tr("message box"));
msgbox->setText("Please wait patiently......")
msgbox->show();
/* parse file and draw */
......
}
But it shows like also be frozen:
How to realize it?
show() does not actually show the content of the dialog. It only tells the event loop to show the dialog ASAP. But since you call more code after immediately after show(), the evnt loop does not have a chance to do its work.
The easiest way to solve this is to call QCoreApplication::processEvents() after msgbox->show(). This will force the event loop to do the work immediately.
If this does not work then try this parameter QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents)
Another option would be to move the heavy calculation to a function and than show the dialog and then schedule the calculation using a timer.
...
msgbox->show();
QTimer::singleShot(0, &doHeavyWork);
This would first handle all events related to showing the dialog and only after that it will start the heavy work (i.e. parsing the file).

when the event loop starts in Dart and how the event queue works

The first question is when the event loop starts ?
I read in a site that it's start after the main method
but why when we try something like this
main()async {
Future(()=>print('future1'));
await Future(()=>print('future2'));
print('end of main');
}
//the output is :
//future1
//future2
//end of main
in this example the event loop start when we use the await keyword and
after the event loop reaches the future2 it's paused ?
or i am wrong :(
The second question is how the events is added to event queue
if it's FIFO why in this example the future 2 is completed before
future 1
main(){
Future.delayed(Duration(seconds:5) , ()=>print('future1'));
Future.delayed(Duration(seconds:2) , ()=>print('future2'));
}
The event loop run when there is nothing else running (e.g. main method is done, you are waiting for some future to complete).
Your example makes sense because the first line puts an event on event queue so now the first item in the queue is "print('future1')". In the next line, you are putting another event on the queue which calls "print('future2')" and now you await for this event to be done.
Since your main method is not waiting for something then the event loop is going to be executed. Since the first event on the queue was "print('future1')" then this is going to be executed first. But since the main method is still waiting for the future "print('future2')" to be complete then the event loop takes another event to be executed which are going to be "print('future2')".
Since this event was the one the main method was waiting for (and there is no more event on the event queue) then main() are going to run the last call "print('end of main')".
In your next example, you think that Future and Future.delayed are the same which it is not. With Future.delayed there are not going any event in the event queue before. Instead, there are running a thread outside the VM which knows when the next timer should trigger which ends up putting an event on the queue. So the event is only being put on the event queue when the timer has been expired (and therefore, the future2 are going to be executed first).

Sleep for x seconds before running next operation

I have been trying in various ways to make my program sleep for 10 seconds before running the next line of code.
this.SetContentView (Resource_Layout.Main)
let timer = new System.Timers.Timer(10000.0)
async{do timer.Start()}
this.SetContentView (Resource_Layout.next)
I can't get any solution to work.
If you want to use async rather than the more direct way (of creating a timer and setting the content view in the event handler of the timer), then you need something like this:
this.SetContentView (Resource_Layout.Main)
async{
do! Async.Sleep(10000.0)
this.SetContentView (Resource_Layout.next) }
|> Async.StartImmediate
The key points:
Using do! Async.Sleep you can block the execution of asynchronous computation
By moving the SetContentView call inside the async, it will happen after the sleep
Using Async.StartImmediate, you start the workflow - and the sleeping ensures that the rest of the computation runs in the same threading context (meaning that it will run on the UI thread and the code will be able to access UI elements).

windows should not respond for given duration in c# or silverlight

example- as i clicked on button , output window should come but it should be like blurred or wait for some time (like something is executing in background).. after some time window should be in activate mode.
could you help me to achieve this without using thread.sleep method ?
Then, you could use a stopwatch , set it for the amount of time you need and then disable all controls of your application(Winform?Silverlight?)
Then you just loop until the stopwatch as finished, or display some kind of Processing label.
While(stopwatch.IsRunning)
{
//Do nothing
}
BTW: This is a synchronous operation, if there's something the thread needs to do while user input is on hold you can't use that.

removing timer is not working

How do I correctly remove/stop a timer in actionscript?
I do it like in this piece of code but timer has been set to fire frame1SoundTimerHandler in 200 seconds later :
playingScreenFramesObj.myTimer2.stop();
playingScreenFramesObj.myTimer2.removeEventListener(TimerEvent.TIMER, frame1SoundTimerHandler);
playingScreenFramesObj.myTimer2 = null;
It seems that despite stopping/removing the timer with the code above the handler will run in 200 seconds.
Where is the mistake I make?
Chris
You should only have to call timer.stop(). As a failsafe you could always check timer.running from inside the event handler.
That code should work. Are you positive you are calling stop on the correct timer? For example, could you accidentally be using timer1 and stopping timer2?

Resources