Hello Guys..

I see, I have been using GCD and blocks but on somme OSX app I did before, not 
on iPhone, I tough tit wasn't there... :P. 

SO, I from within the method( block) that makes all the saving process, I do 
something like 

>>      dispatch_async(dispatch_get_main_queue(), ^{
>>         // code executed on main thread goes here (i.e., updating the 
>> progress indicator in your case
>> 
>>      });


and update the progress indicator bar,  great im gonna try that..

also I have the option to call from within the same method a  [<MyConotroller 
With the Progress indicator> performSelectorinMainThread: withObject:<NSNumber 
with the float value to add> waitUntilDone:NO];  

right?


What about the saving operation improving its saving time?,  I will check today 
what takes longer, if creating the thumbnial, or encoding the views,  maybe I 
shouldn't encode the whole view, but s just the image reference and the 
transform matrix...  ?/ I will try that one also.

Thanks for the replies.. 


Gustavo


On Dec 7, 2010, at 4:22 AM, davel...@mac.com wrote:

> 
> On Dec 6, 2010, at 9:21 PM, Laurent Daudelin wrote:
> 
>> On Dec 6, 2010, at 17:16, davel...@mac.com wrote:
>> 
>>> On Dec 6, 2010, at 5:37 PM, Gustavo Pizano wrote:
>>> 
>>>> Hello.
>>>> 
>>>> My application is saving some data, and it takes a while to do it, it can 
>>>> be 1 second to 10 sec around.. Im doing some image processing,  The thing 
>>>> is..
>>>> 
>>>> I send the saving operation in another thread using the NSThread + 
>>>> detachNewThreadSelector:toTarget:withObject: method,  and in the main 
>>>> thread I update a UIActivityIndicator, and stop it when I receive the 
>>>> NSThreadWillExitNotification.  The problem is that when it takes long to 
>>>> save, it may seem the app is somehow stuck, even the spinning indicator is 
>>>> running. I wanted to change the ActivityIndicator to a progressview, but 
>>>> then I can't make it work because the saving process not on the main 
>>>> thread, i think.. correct me if Im wrong, Im not so much familiar with 
>>>> multithreaded apps.
>>>> 
>>>> As for the saving process, what I do is the following.
>>>> 
>>>> I have a Parent view which contains subviews, these subviews are drawing 
>>>> images. The user can modify this images, (scale and rotate), so when I 
>>>> save i encode these views so it will save the view's transform,  and then  
>>>> I archive the data I encoded for all these subviews.
>>> 
>>> 
>>> <your code deleted>
>>> 
>>> You are correct that you cannot call GUI methods from other threads, but 
>>> NSObject (which all your UI objects inherit from) has the method.
>>> 
>>> - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg
>>> 
>>> So from your other thread, you can update the progress indicator by using 
>>> it to call a method that updates the progress. 
>>> 
>>> 
>>> This is even easier if you are targeting iOS 4.0 and higher using Blocks 
>>> and GrandCentral Dispatch.
>>> 
>>> Code typed in email (i.e., not tested):
>>> 
>>> dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 
>>> 0), ^{
>>>      // code you want implemented on another thread goes here:
>>> 
>>>      dispatch_async(dispatch_get_main_queue(), ^{
>>>         // code executed on main thread goes here (i.e., updating the 
>>> progress indicator in your case
>>> 
>>>      });
>>>  });
>>> 
>>> HTH,
>>> Dave
>> 
>> Maybe I'm missing something but aren't the UI actions supposed to happen in 
>> the main thread, in this case, he should really call 
>> "performSelectorOnMainThread:withObject:waitUntilDone:"?
>> 
>> -Laurent.
> 
> 
> I copied and pasted the wrong method. Yes, the onMainThread version is the 
> one to use for this.
> 
> The Grand Central Dispatch code is ok though as Conrad pointed out.
> 
> Dave
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/gustavxcodepicora%40gmail.com
> 
> This email sent to gustavxcodepic...@gmail.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to