Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Dec 17, 2017 8:29 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: shell running and progressbar vs progresswhell usage?
PostPosted: Fri Mar 08, 2013 5:22 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Hi,
i run an shell (in Mode 0 = Main App waits for finishing) for a fixed time of 15 sec.
I want to show progessbar while the shell is running.

Why the Main App dosnt update the progressbar?!
I put an timer (Main App) which was enabled before starting the shell but it is never fired (so no updates in the progressbar). Why?!
The Timer , and the progressbar starts running when the shell is finished. :(
I understand that the programmcode after the shell call is not computed until shell is finished - but an timer should run complete independed from any shell - even in mode 0.

Cant RB handle at least such things like timer beside running an shell (in mode 0!) ?
I havent used the #pragma for disabling background tasks - in such case i would understand RB "sleeps" complete and even not fires the timer.

PS: I dont want to poll for shell is running in an loop to avoid cpu load.

I fear putting the shell in an thread or putting the timer in an thread wouldnt help to compute progressbar (by timer action).
But perhaps some other way possible?

EDIT: I am on OS X Intel, RS 2.1
Tried to run the timer (which try to update the progressbar) in an THREAD - but also nothing happens until shell exits. timer firex after shell is exit :(

Can it be that its because the THREAD / timer is parent of the window? And so cant be fired even if use an own thread?
How could i put the thread into an perhaps "own" app parent way?


Last edited by mitch_stgt on Tue Mar 12, 2013 6:02 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Fri Mar 08, 2013 2:22 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
mitch_stgt wrote:
Hi,
i run an shell (in Mode 0 = Main App waits for finishing) for a fixed time of 15 sec.
I want to show progessbar while the shell is running.

Why the Main App dosnt update the progressbar?!
I put an timer (Main App) which was enabled before starting the shell but it is never fired (so no updates in the progressbar). Why?!
The Timer , and the progressbar starts running when the shell is finished. :(
I understand that the programmcode after the shell call is not computed until shell is finished - but an timer should run complete independed from any shell - even in mode 0.

Incorrect. *Nothing* happens in your app while a mode 0 shell is processing. You should use Mode 1 (async) and check the shell's status in a timer.

Quote:
Cant RB handle at least such things like timer beside running an shell (in mode 0!) ?

No.

Quote:
I havent used the #pragma for disabling background tasks - in such case i would understand RB "sleeps" complete and even not fires the timer.

Doesn't apply here.

Quote:
PS: I dont want to poll for shell is running in an loop to avoid cpu load.

Definitely wouldn't advise polling in a loop. Use a timer.

Quote:
I fear putting the shell in an thread or putting the timer in an thread wouldnt help to compute progressbar (by timer action).

Correct. It wouldn't help. RB threads are cooperative. The shell would still block the thread, which in turn blocks the entire app.

Quote:
But perhaps some other way possible?

Use an asynchronous shell (mode 1 or 2).


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Fri Mar 08, 2013 3:05 pm 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Thanks!
I will try asyncron shell. (and use an timer to update progressbar and readall for the result). Hope i must not use an thread for the timer.
But too bad that an mode 0 shell blocks even timer (events). I understand that the app must wait for finishing that shell and then working next commands in the app. But blocking timer, which runs always in background?! Looks not OOP.


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Fri Mar 08, 2013 6:40 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
It's not an OOP issue, it's an event-driven issue. Timers do not run "in the background". They run as part of the event loop. If anything blocks the event loop (which runs in the main thread), it by definition blocks any timers.
Quote:
Hope i must not use an thread for the timer.

Not trying to be nit-picky, but that statement doesn't even make sense. You cannot run a timer inside a thread. They always run as part of the event loop in the main thread. That's what makes them so useful in a threaded app (your async shell can be thought of as a thread). Even if a thread instantiates and starts a timer, it still runs completely separate from the thread that created it.


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Fri Mar 08, 2013 7:38 pm 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Thanks for explaining the background.

My old code (which runs, but hasnt an progressbar) looks like.
// main window code
my_shell.Mode = 0 // syncro, app waits shell for finishing
my_shell.execute = "commandlineapp arg"
// shell runs now
result_string = my_shell.result
// now steps computing the result


new code (first without progressbar usage) ?
my_shell.Mode = 1 // async , app waits not for finishing
my_shell.execute = "commandlineapp arg"
HOW WAIT NOW FOR FINISHING the shell ? loop like wait until my_shell.running?
I cant do next steps without having the my_shell.result
// now steps computing result, like sycro mode


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Fri Mar 08, 2013 7:51 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
// main window code
my_shell.Mode = 1 // async
my_shell.execute("commandlineapp arg")

// my_shell.completed event code
result_string = me.ReadAll
steps computing the result


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Sat Mar 09, 2013 3:01 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Yes, but were put the my_shell.completed event code?

Before i had an linear code:
call shell mode 0
result = my_shell.result
compute shell result
..

if i use asyc the compute shell result , first step is search some string by Instr() must wait before i can readall and access the result.
so were / how must i wait? Were put that execute shell & wait for finish & readall (like calling an subroutine).


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Sat Mar 09, 2013 3:49 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
The shell fires an event, Completed, when it finishes. Until then, your app does nothing. So you start the shell and return. Nothing happens until the shell finishes and fires its Completed event. There is *no code running* in your app in the mean time. Put your code in the Completed event of my_shell. There are 3 ways to do it

Put a shell on the window.
Make a subclass of shell.
Use AddHandler to tell my_shell what code to run in its Completed event.


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Sat Mar 09, 2013 6:36 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
"The shell fires an event, Completed, when it finishes. Until then, your app does nothing."
But i tried mode 1(shell runs beside app) and the programcode after the my_shell.execute - the command which was result_str = my_shell.result was computed immediatly (before shell finished) so app not nothing in mode 1. So i asked how to wait for shell finished before i compute the result.


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Sat Mar 09, 2013 1:49 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
There should be no code after shell.Execute. Simply return from the method. Move the code that was after shell.Execute to the shell's Completed event.

How are you creating the shell?

1) By dragging a shell onto the window and naming it my_shell?
2) By dim'ing a variable of type shell and calling new shell?
3) By using a window (or module) property of type shell, and calling new shell?

At your level of expertise (and here I'm assuming), I would recommend #1. Put a shell object onto your window. Then in the code editor under the shell, you will see the Competed event. Put your code in there to compute the result.


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Mon Mar 11, 2013 7:18 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
timhare wrote:
There should be no code after shell.Execute. Simply return from the method. Move the code that was after shell.Execute to the shell's Completed event.
.


Thanks! That was my problem, because i used DIM my_shell as shell to create the shell and not the drag&drop shell container. So i havent any "place" for the complete event to put.

Now its clear :)

PS: I found in the forum an other which has same problem - used DIM to create shell and not the drag&drop shell which creates the places / events for the shell.


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar?
PostPosted: Tue Mar 12, 2013 4:57 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Too bad: I cant find any shell object in the left object list to drag&drop into the window. Using RS 2.1.
EDIT: Solution - i took OBJECT onject and changed super to shell.

Now the shell works in background (MODE1).
I can use progresswheel to show that something happens (while shell is running in Mode 1) - it starts spinning while shell is running. (comment: If i would use Mode 0 progresswheel would not spin.)

But i can not (tested with thread or timer coded updates) update the progressbar while shell is running in mode 0!
I understand that the progresswheel has an buildin update (spins) and the progressbar needs some compute code from "outside".
But how can i get the progressbar updated like the progresswheel spins when using Mode 1 in shell (updates own without code from outside)?


Top
 Profile  
Reply with quote  
 Post subject: Re: shell running and progressbar vs progresswhell usage?
PostPosted: Wed Mar 13, 2013 12:22 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
What would you update it to? Since you don't know how much progress (out of the total) has been achieved, the best you can do is an indeterminate progress indicator, such as the progresswheel. Or set the progressbar maximum to -1, I think.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group