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

  • Home
  • SEARCH
  • 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 6660065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:06:31+00:00 2026-05-26T02:06:31+00:00

I attempt to write a file in thread because it freeze my app when

  • 0

I attempt to write a file in thread because it freeze my app when writing but when i launch writing process it crash

2011-10-04 21:53:51.022 xxxxxxxxx[2046:6603] *** Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle seekToEndOfFile]: Operation timed out'

my code:

- (void)WriteTest{
    [NSThread detachNewThreadSelector:@selector(DoWriteTest:) toTarget:self withObject:hFile];
}

- (void)DoWriteTest:(NSFileHandle *)aHandle{
    int i;

    if (aHandle)   {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

        NSLog(@"---start--- writing test file --");
        for (i=0; i<1024*1024; i++) {
            [aHandle seekToEndOfFile];
            [aHandle writeData:[NSData dataWithBytes:bytes length:(sizeof bytes) - 1]];
            usleep(1);
        }

        NSLog(@"---end--- writing test file");

        [pool release];
    } else {
        NSLog(@"ERROR: writing test file thread");
    }
}

when i did this without a thread this code work, can you explain me what i’m wrong please, i make a lot of google search but i don’t find a solution. Thanks.

  • 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-26T02:06:32+00:00Added an answer on May 26, 2026 at 2:06 am

    Your code worked for me. My guess is you opened your file handle incorrectly. Also note that you should use [pool drain] instead of [pool release], but this is nitpicking. My full code is below. Comment if you have any questions. Hope it helps.

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        fileHandle = [NSFileHandle fileHandleForWritingAtPath:@"/Users/Drew/Desktop/test.txt"];
        [NSThread detachNewThreadSelector:@selector(threadSelector:) toTarget:self withObject:fileHandle];
    }
    
    - (void)threadSelector:(NSFileHandle *)aHandle {
        if (aHandle)   {
             NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
             int i;
             for (i=0; i<1024; i++)
             {
                 [aHandle seekToEndOfFile];
                 char buffer[1024] = "a string ";
                 [aHandle writeData:[NSData dataWithBytes:buffer length:(sizeof buffer) - 1]];
                 usleep(1);
             }
             [pool drain];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I attempt to open a file to write, I get an error: Ada.IO_Exceptions.Name_Error
Following is my attempt to write BK-Tree , for 150000 word file it takes
Suppose my attempt to write a pickle object out to disk is incomplete due
I'm trying to write a Date class in an attempt to learn C++. I'm
I want to write an Exception to an MS Message Queue. When I attempt
I'm attempt to debug a program I wrote, but I'm running into a problem
I have two different PHP files that both write to the same file. Each
I trying to write a char[256] to a text file. Below is my current
I'd like to write a log record in case of a failed attempt of
I'm pulling in a 3rd party JavaScript file which makes use of document.write ,

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.