performSelectorInBackground and performing UI Operation
<p>In application I need to take Image out of UIView. Frame of that View is W 1800 and H 1200.</p>

<p>This activity takes lot time and screen stucks there unless this activity get finish. </p>

<p>I need to perform this activity in background,so that user can continue with other things.</p>

<p>What is best approach to achive this. I tried with </p>

<pre><code>- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg
</code></pre>

<p>But application get crash as it doesn't allow UI operation with this. If I go with </p>

<pre><code>- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
</code></pre>

<p>screen stucks there unless this activity get finish.</p>

<p>I need to perform following activity in background</p>

<pre><code>-(void) PrepareImageData
{
    UIImage* frontViewImage = [self PreparefrontImage:[self GetSavedFrontImage]];
    [self SaveImageinDocumentWithName:frontViewImage FileName:@"frontview.png"];

    UIImage* rearViewImage  = [self PrepareBackImage:[self GetSavedBackImage]];;
    [self SaveImageinDocumentWithName:rearViewImage FileName:@"backview.png"];
}
    -(UIImage*) GetSavedBackImage
    {
        UIImage* background;
        UIImage* messageTextview;
        UIImage* toTextView;
        UIImage* fromTextView;

        background      = [self GetImageFromView:self toRect:self.frame];

        CGRect rect = CGRectMake(0, 0, 1800, 1200);
        UIGraphicsBeginImageContext(rect.size);
        CGPoint backgroundPoint = CGPointMake(0,0);
        [background drawAtPoint:backgroundPoint];
        UIImage* backImage = UIGraphicsGetImageFromCurrentImageContex();
        UIGraphicsEndImageContext();

        return backImage;
    }

    - (UIImage *) GetImageFromView:(UIView *)aView toRect:(CGRect)aRect
    {
        CGSize pageSize = aRect.size;
        UIGraphicsBeginImageContext(pageSize);
        [aView.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;

    }
</code></pre>

<p>Please help me on this.</p>

<p>Thanks.</p>
