gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSProgressIndicator movement inside a loop


From: Frederico Muñoz
Subject: Re: NSProgressIndicator movement inside a loop
Date: Thu, 03 Mar 2005 11:39:54 +0100

Hello,

Thank you for your answer.

On 2005-03-02 13:00:32 +0000 Fred Kiefer <address@hidden> wrote:

(snipped description of problem with updateing NSPRogressIndicator inside a 
loop)

> 
> Could you explain, what problems you are expecting from this approach?

Er, well, no, I can't :) . I easily confess that I still don't grasp even 
simpler things in GNUstep programming than threads. The problems that were 
raised by people whose expertise largely outweights mine were the possible side 
effects of having the object called inside the secondary thread. I don't know 
the specifics of the side effects and have only a vague suspicion on why they 
would occur, and that's why I wrote the mail.

> As far 
> as I understand, you where just changing the progress indicators state and 
> marking it for redraw (done by IncrementBy:). This should be fine even from a 
> background process. I admit that most of the GUI code isn't currently thread 
> safe, but in this special case no harm should follow. It may be different for 
> your code to display the file name, but you did not give any details on that. 
> What you need to keep in mind is never to draw from a background thread, and 
> this you seem to have respected.

Yes, this was my aim.

> 
>> [sender performSelectorOnMainThread: @selector(updateProgressWithFile:)
>>                       withObject: file waitUntilDone: NO];
>> 
>> to be more thread friendly but this doesnt work, since not having it
>> executing in the main thread (to escape the run loop draw timing) was
>> the reason I created the thread in the first place, and this way the
>> problem reapears, the progress bar is only updated after the loop
>> exits.
>> 
> 
> This approach should work (if you set waitUntilDone to YES), but it is really 
> not needed. 

Yes, it does work with it set to YES, thanks.

Since apparently, both from your answer and from my testing, using a thread in 
this specific situation isn't so bad after all I will stick with it. I have 
substituted the call to the sender's "updateProgress" method to registering the 
main object for the "ProgressShouldUpdate" notification and sending a 
notification inside the installPackage method (run trough NSThread) each time a 
file is processed. I think this is a more suitable mechanism. If I need to send 
information I can put it inside a NSDictionary in the notification, and the 
information will only be needed inside the life of each individual 
updateProgress call.

I have tested this and it works without any problems.


Thank you again for your answer,

fsmunoz
-- 
Frederico Muñoz
address@hidden






reply via email to

[Prev in Thread] Current Thread [Next in Thread]