Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:13:36+00:00 2026-05-28T13:13:36+00:00

My code: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ @autoreleasepool { // Now on a background thread //

  • 0

My code:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        @autoreleasepool {            
            // Now on a background thread

            // Setup background task
            __block UIBackgroundTaskIdentifier bgTask;

            void (^finishBackgroundTask)(void) = ^(void) {
                [[UIApplication sharedApplication] endBackgroundTask:bgTask];
                bgTask = UIBackgroundTaskInvalid;
            };

            // Start background task
            bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:finishBackgroundTask];

            // The method below migrates a core data database and takes ages
            [MyClass migrateCoreDataStuff];

            finishBackgroundTask();
        }
    });

The error I get is NSUnderlyingException = "Fatal error. The database at /var/mobile/Applications/55B83D5F-CCF5-438E-BECA-B97DB5505541/Documents/Blah.sqlite is corrupted. SQLite error code:11, 'database disk image is malformed'";

The migration error only occurs when the following are all true:
* migration is on a background thread
* migration is running as a UIBackgroundTask
* I’m running on the device, not a simulator

I’m running iOS 4.3.5, building for iOS 4.0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:13:37+00:00Added an answer on May 28, 2026 at 1:13 pm

    Without seeing the contents of migrateCoreDataStuff, it’s hard to see the exact problem. However, Core Data on non-main threads is a tricksy issue. Have a read of http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/CoreData/Articles/cdConcurrency.html. You’ll probably need, at a minimum, a separate managed object context for the new thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: dispatch_async(dispatch_get_main_queue(), ^(void) { SEL selector = @selector(callback:); [self.delegate performSelector:selector withObject:self];
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
I've a code alike void ExecuteTraced(Action a, string message) { TraceOpStart(message); a(); TraceOpEnd(message); }
// Method called when a button is clicked - (void)handleClickEvent { dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Hi I am getting a reported leak from Instrument with the following code. dispatch_async(requestQueue,
Why does my code crashes? dispatch_async(queue_A, ^{ @synchronized(self) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]
dispatch_queue_t callerQueue = dispatch_get_current_queue(); dispatch_retain(callerQueue); dispatch_queue_t downloadQueue = dispatch_queue_create(Download Queue,NULL); dispatch_async(downloadQueue, ^{ //some code
On iOS device, I recently found that a strange behavior. Code1: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
In my iPhone app I have a background task that starts running when the
Consider the following code: @interface ClassA : NSObject @property (nonatomic, copy) void(^blockCopy)(); @end @implementation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.