New topic: 

Threads and timers

<http://forums.realsoftware.com/viewtopic.php?t=46230>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        DanSandbergUCONN          Post subject: Threads and 
timersPosted: Thu Dec 13, 2012 11:41 am                         
Joined: Fri Dec 21, 2007 9:50 am
Posts: 200                Hi All-

I've nested code in a thread, let's call it AwesomeThread, and I am monitoring 
the thread's progress using a loop. The thread has a constructor method I use 
to pass it variables on instantiation. In a pushbutton's action event I have 
something like:

dim myThread as new AwesomeThread(arg1, arg2, arg3)
//arg1, arg2, and arg3 are values obtained from the window in which this 
pushbutton is located
myThread.run
do
  myProgressBar.Value=myThread.progress
  //myThread.Progress is a property of the myThread object
  app.doevents()
loop until ThreadIsDone
//ThreadisDone is a property of the local window, which is default false but 
set to true by the thread when the thread is done.

Now I would prefer to use a timer rather than app.doevents. But if I put the 
code within the do loop into a timer, the timer won't have access to the 
myThread variable, which is an instantiation of AwesomeThread. I could move the 
myThread.Progress variable to global variable called Progress but then if I 
instantiate two copies of the thread both copies would try to update the Global 
'Progress' variable at the same time. 

I'm sure there is an easy way to monitor a thread with a timer but I'm drawing 
a blank at the moment. Thanks in advance for the help.   
                             Top                DanSandbergUCONN          Post 
subject: Re: Threads and timersPosted: Thu Dec 13, 2012 1:04 pm                 
        
Joined: Fri Dec 21, 2007 9:50 am
Posts: 200                ...Wait, is the answer to declare the myThread 
variable as a global property and then just do the instantiation in the 
pushbutton? ... I can't think of any reason that would NOT work. Is that the 
simplest / most common way to set up a thread and monitor that thread's 
progress?   
                             Top                charonn0          Post subject: 
Re: Threads and timersPosted: Thu Dec 13, 2012 1:26 pm                          
       
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1044
Location: San Francisco, CA, USA                Making it global should work 
fine.      
_________________
Boredom Software  
                             Top                ktekinay          Post subject: 
Re: Threads and timersPosted: Thu Dec 13, 2012 3:09 pm                          
       
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 311
Location: New York, NY                DanSandbergUCONN wrote:...Wait, is the 
answer to declare the myThread variable as a global property and then just do 
the instantiation in the pushbutton? ... I can't think of any reason that would 
NOT work. Is that the simplest / most common way to set up a thread and monitor 
that thread's progress?
Yes. If you need more than one of these threads, declare your global as an 
array and use it like a stack. Periodically delete or reuse the threads that 
finish.

Your property can either be in a module, or as a property of the window.      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to