Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 17, 2008, 06:37 PM   #1
alvises
macrumors newbie
 
Join Date: Jul 2008
NSThread blocks interaction

Well, about uiview update and nsthread: I want to do an example to show better the BIG problem:

I start a thread with

[NSThread detachNewThreadSelector:@selector(mainloop toTarget:self withObject:nil];

This "mainloop" method is like

-(void)mainloopid)object{
while(YES){
NSString *line = [stream readLine];
//console is UITextView object
console.text = line;
}
}

Well, when I start the thread the application continues to work. When i receive the first line (and then when the thread modify for the first time a object of the GUI) the USER interaction is BLOCKED. All the GUI (bottons, tables, not only "console textview") is refreshed ONLY every while loop and (when i receive another line) and then if I want to see the update i have to wait the next line........
Why ?
I'm getting crazy with this problem.
Thanks.

Alvise
alvises is offline   0 Reply With Quote
Old Jul 18, 2008, 05:22 AM   #2
alvises
Thread Starter
macrumors newbie
 
Join Date: Jul 2008
Yea. I have founded a solution. Well , I try to explain with my bad english.

this is the pseudocode:

-(IBAction)methodInMainThreadid)button{
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(separatedThread userInfo:nil repeats:YES];
}

-(void)separatedThreadNSTimer*)timer{
NSString *line = [input readlineWithTimeout:0.01];
if(line == NULL)//timeout
return;

//process the string
}


In this case i write the code of a "readLineWithTimeout:" method. This method waits for a input for 0.01 seconds, after that returns and the gui will be updated.
The POSIX function to use to "select" the input and know if it goes in timeout is "select()" function -> "man select".

I don't know if is the best way to resolv the problem.... a thread looping every 10 millisecs is not the best way i think.... but it works!
Any comment ?

Thanks.

Alvise
alvises is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Announcing Wild Fables - Interactive Book w/ Physics! (Universal App) Ray Wenderlich iPhone and iPod touch Apps 4 Aug 20, 2011 08:47 AM
No more nappy! : an interactive book for iPad matt78 iPad Apps 0 Apr 20, 2011 08:56 AM
Interactive Nighty Night! HD for iPad makes going-to-bed ritual easier Euforia iPad Apps 2 Apr 19, 2011 05:54 AM
New Interactive Book for Children matt78 iPad Apps 3 Feb 15, 2011 03:15 AM
Interactive French learning apps AquaDolphi iPhone and iPod touch Apps 0 Nov 15, 2010 03:20 PM


All times are GMT -5. The time now is 02:03 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC