New topic: 

Calling a Method from a Thread?

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

         Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic          Author  
Message        Tommyknockers          Post subject: Calling a Method from a 
Thread?Posted: Thu Nov 08, 2012 3:03 am                         
Joined: Sun Jul 15, 2007 3:12 am
Posts: 100
Location: Denmark                Hi all,

I'm doing a simple backup app, that copies files or folders dropped onto its 
main window, to a pre-defined destination like a users Dropbox. This works 
fine, but when trying to implement a ProgressBar, this is not updated until the 
file copying has finished. I suppose this is because I'm not threading the file 
copying code, so I have adapted the code from the Threaded UI Update example 
that comes with Real Studio.

And this actually work too, except that the ProgressBar still does not run 
until the file or folders has been copied - it's the exact same as before 
implementing the thread and timer from the example.

Is this behavior perhaps because I'm not doing anything else from Thread1.Run 
than calling my BackupFileOrFolder method, where the actual file copy is done? 
To put it another way, are methods called from a threads Run event not 
threaded, but runs along all the other code?

If so, how do I make a method threaded? Looking at my code, I suppose I could 
alter it to run directly inside the threads Run event, but people must have 
methods that need threading, so I'd love to learn how this is done ... if that 
indeed is my problem?
Or can it have something to do with the way I've modified my BackupFileOrFolder 
method, with the code from the Threaded UI Update example? In this method I set 
the mProgressValue property to zero at the very beginning, and then wrap the 
file/folder copying code in a While/Wend loop that updates the property and 
ProgressBar - should this update be done another way when copying files and 
folders perhaps?
Anyways, those were a couple of things I think could be the cause. Any help and 
input I can learn from, will be greatly appreciated! :)

PS: By the way, this is under Mac OS X Mountain Lion using RS 2012 1.1 Pro. 
During testing the file copying is done to a folder on my hard drive, and not 
to a Dropbox folder.      
_________________
REAL Studio 2012 Pro, on a 17" MacBook Pro running Mac OS X Mountain Lion.      

    Last edited by Tommyknockers on Thu Nov 08, 2012 3:13 am, edited 1 time in 
total.   
                             Top                timhare          Post subject: 
Re: Calling a Method from a Thread?Posted: Thu Nov 08, 2012 3:12 am             
            
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11783
Location: Portland, OR  USA                Methods called from a thread are 
threaded.  But you have to make sure that the thread yields enough time back to 
the UI to allow it to update the screen.  Threads can yield at loop boundaries, 
but they don't necessarily do.  You may have to sprinkle some Yield or Sleep 
calls into your threaded code.  You can adjust how often you yield to tune the 
performance of the app.   
                             Top                Tommyknockers          Post 
subject: Re: Calling a Method from a Thread?Posted: Thu Nov 08, 2012 3:16 am    
                     
Joined: Sun Jul 15, 2007 3:12 am
Posts: 100
Location: Denmark                Wow, that was fast Tim :)

I'll look at that in an hour - why do family always visit when you're having 
the most fun learning? ;-)

Thank you so much, I'll report back when they're gone!

Cheers,
Thomas      
_________________
REAL Studio 2012 Pro, on a 17" MacBook Pro running Mac OS X Mountain Lion.  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 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