• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Updating a Static Text and Slider From High Priority Thread While Resizing a Window [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating a Static Text and Slider From High Priority Thread While Resizing a Window [SOLVED]


  • Subject: Re: Updating a Static Text and Slider From High Priority Thread While Resizing a Window [SOLVED]
  • From: Peter Zegelin <email@hidden>
  • Date: Mon, 20 Oct 2008 14:38:30 +1100

Actually I just found an old thread:

'Problem redrawing views while window resize button is held'

and the suggestion was to use [window displayIfNeeded]; to force a window update. This works, so problem solved.

Thanks again,

Peter



On 20/10/2008, at 2:33 PM, Peter Zegelin wrote:

Thanks for your reply Andrew. Unfortunately it still doesn't work. The text or slider don't update at all if I click and hold on the resize widget. It will only update if I move the mouse and it is very 'jerky' even when I do that.

Here is what I have. UpdatePosition is called from my thread and I have simplified a few things.:

- (void)updatePosition:(id)anObject{
   NSAutoreleasePool	*pool = [[NSAutoreleasePool alloc] init];

while (1) {

myStopWatch->updatePosition();

[self performSelectorOnMainThread:@selector(updateGUI) withObject:nil waitUntilDone:NO];

[NSThread sleepForTimeInterval:.001];

std::cout << "MainThread " << myStopWatch->getPosition(); << std::endl;
}


   [pool release];
}


- (void)updateGUI{
double currentPosition;


currentPosition = myStopWatch->getPosition();

[ positionLabel setDoubleValue: currentPosition];
[ positionLabel setNeedsDisplay:YES];

std::cout << "GUI Thread" << currentPosition << std::endl; <-- this doesn't block
}


As you can see updateGUI is being called all the time as std::cout keeps spitting out data, but my text label doesn't update at all. It is as if clicking on the resize widget runs in its own loop and only updates the window when it actually changes size. Interestingly an app such as GarageBand also stops updating its GUI if a song is playing and you click and hold on the resize widget.

Peter




On 19/10/2008, at 1:36 PM, Andrew Merenbach wrote:


On Oct 18, 2008, at 7:27 PM, Andrew Merenbach wrote:

On Oct 18, 2008, at 4:23 AM, Peter Zegelin wrote:

Hi,

Still fairly new to Cocoa here.

I have a high priority thread that that for the moment just calls back as often as possible to a method that updates a static text object with the current time. A slider is also updated to a new value. Its a bit like a stop watch with a position indicator. This all works well until I resize a window or invoke a menu when the whole thing just grinds to a halt. If I call std::cout with the value the debugger shows a continuous stream of data so I know the thread is still being called as often as possible but the text and slider aren't updating. Is there any way to get these items to update under these circumstances? I tried calling [label setNeedsDisplay] but that just caused a crash.


thanks!

Peter Zegelin

Hi, Peter,

Is it possible that your GUI objects are being updated from the secondary thread? You'll need to use - performSelectorOnMainThread: to channel updates from the high- priority thread to the main thread, since only the main thread is allowed to touch the graphical AppKit classes (which are generally not threadsafe, with the possible exception of NSProgressIndicators). Hopefully this solves your issue!

Cheers,
	Andrew


Erm, sorry to respond to myself, but I was lazy -- just for clarity, the full methods available are (from the docs):


- (void)performSelectorOnMainThread:(SEL)aSelector withObject: (id)arg waitUntilDone:(BOOL)wait;
- (void)performSelectorOnMainThread:(SEL)aSelector withObject: (id)arg waitUntilDone:(BOOL)wait modes:(NSArray *)array;


-- Andrew


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Updating a Static Text and Slider From High Priority Thread While Resizing a Window (From: Peter Zegelin <email@hidden>)
 >Re: Updating a Static Text and Slider From High Priority Thread While Resizing a Window (From: Andrew Merenbach <email@hidden>)
 >Re: Updating a Static Text and Slider From High Priority Thread While Resizing a Window (From: Andrew Merenbach <email@hidden>)
 >Re: Updating a Static Text and Slider From High Priority Thread While Resizing a Window (From: Peter Zegelin <email@hidden>)

  • Prev by Date: Re: Updating a Static Text and Slider From High Priority Thread While Resizing a Window
  • Next by Date: Mutable arrays
  • Previous by thread: Re: Updating a Static Text and Slider From High Priority Thread While Resizing a Window
  • Next by thread: Application quit in NSBeginAlertSheet
  • Index(es):
    • Date
    • Thread