Update tableview with regular time intervals in iphone
<p>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.</p>

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

<p>In that timer function i have called NSThread function.</p>

<pre><code>-(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");

}
</code></pre>

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

<pre><code>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...
</code></pre>

<p>What is wrong with my code? Crashes appear randomly.</p>
