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 6469071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:56:59+00:00 2026-05-25T05:56:59+00:00

I have created a sample application. It has fetched data from server for every

  • 0

I have created a sample application. It has fetched data from server for every 1 sec and updated the result in UITableView. I had already done. But it crashes my app rapidly. What I do is call NSTimer every sec.

timer = [NSTimer scheduledTimerWithTimeInterval:1
                                         target:self 
                                       selector:@selector(MainLoop) 
                                       userInfo:nil repeats:YES];

In that timer function i have called NSThread function.

-(void)MainLoop
{
  if(isPreviousThreadFinished)
  {
    NSLog(@"Thread Opened");
    isPreviousThreadFinished = NO;
    [NSThread detachNewThreadSelector:@selector(MainLoopThread) toTarget:self  withObject:nil];
  }
}



-(void)MainLoopThread
{

MainLoopPool=[[NSAutoreleasePool alloc]init];

//Get data from the server

[self performSelectorOnMainThread:@selector(UpdateTable) withObject:nil waitUntilDone:YES];


[MainLoopPool release];
}

-(void)UpdateTable
{
    [self.tableView reloadData];
    isPreviousThreadFinished = YES;
    NSLog(@"Thread closed");

}

It works fine. And reloads data correctly from the server. I stop NSTimer in viewWillDisappear method. When I go to previous page sometimes it crashes application. In console i have seen the error is given below,

bool _WebTryThreadLock(bool), 0xb2aa410: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

What is wrong with my code? Crashes appear randomly.

  • 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-25T05:56:59+00:00Added an answer on May 25, 2026 at 5:56 am

    When I work on my application I discovered very good thing – NSOperation. It’s thread safe. You can simply add you operations to the queue without fear to crash. There are a lot of tutorials about NSOperation

    http://www.icodeblog.com/2010/03/04/iphone-coding-turbo-charging-your-apps-with-nsoperation/
    http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/

    I strongly recommend you use NSOperation-s instead of threads in your project.

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

Sidebar

Related Questions

I have created a simple win 32 application..in which it has a textbox and
I have created a sample java socket application. I used Socket s = new
Background: I have created sample windows application for learning to implement localization. My each
I have been attempting to compile/run a sample WCF application from Juval Lowy's website
I have created sample application that insert 12 rows in tableview.And inserted fine.When after
I have created a simple application which has a scroll bar. The scroll bar
I have created a simple blog application with Ruby on Rails. The applications consists
I created a simple ASP.NET MVC version 1.0 application. I have a ProductController which
I have created a sample report with crystal report 10. Now, I wanna to
I have a query that I'm executing from a .NET application to a SQL

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.