• 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: NSPanel as Sheet and controlling the run loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPanel as Sheet and controlling the run loop


  • Subject: Re: NSPanel as Sheet and controlling the run loop
  • From: Vincent Coetzee <email@hidden>
  • Date: Thu, 8 Apr 2004 09:40:45 +0200

Dear Guys,

I would like to point out that ideally processing should not be done in the UI thread, since then the user interface essentially freezes (apart from the updating of the progress bar) until the processing completes. I am not sure what Apple's point of view is on the maximum amount of time that an in-UI thread task should take, but most experts tend to suggest that if something takes longer than 1/10 of a second (100ms) then it should not ideally be done in the UI thread since that is the limit of visual perception.

If processing is going to take longer than this amount of time, then rather decouple the processing from the UI thread by spawning another thread that actually does the processing and reports back to the UI by sending notifications of progress via NSNotificationManager. The use of notifications nicely decouples the two threads. I personally do not like using NSNotifications, and use a model based on the Smalltalk dependency patterns, although this introduces some additional complexity in terms of making sure two threads do not attempt to access shared data at the same time, which is not a problem when using NSNotifications.

Hope this comment is of value.

Vincent


On Apr 07, 2004, at 19:34, Larry Fransson wrote:

I'm sure you'd figure it out eventually like I did. But to help you along, here's some code that I have used. It opens a window as a sheet (I'm sure a panel will work just fine as well) with a progress bar and some descriptive text. It runs while some file processing is going on, and then closes when the process is finished.

[NSApp beginSheet:indexWindow
modalForWindow:mainWindow
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];

session = [NSApp beginModalSessionForWindow:indexWindow];
[indexProgressText setStringValue:@"Reading the new data file..."];
[indexProgressBar setUsesThreadedAnimation:YES];
[indexProgressBar startAnimation:self];
[NSApp runModalSession:session];

dataString = [[NSString alloc] initWithContentsOfFile:[sheet filename]];
[indexProgressBar setIndeterminate:FALSE];
[indexProgressBar setMinValue:0.0];
[indexProgressBar setMaxValue:(double)[dataString length]];
[self indexDataFromString]; // This method also updates the progress bar and
// the text in the progress window.

// Processing finished - close the sheet
[NSApp endModalSession:session];
[NSApp endSheet:indexWindow];
[indexWindow orderOut:self];

I don't remember now what happened before I put the "orderOut:" in there at the end. I only remember that it didn't work exactly right until I did.

Larry Fransson
Seattle, WA
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: NSPanel as Sheet and controlling the run loop
      • From: "Louis C. Sacha" <email@hidden>
References: 
 >NSPanel as Sheet and controlling the run loop (From: "Alexander F. Hartner" <email@hidden>)
 >Re: NSPanel as Sheet and controlling the run loop (From: Larry Fransson <email@hidden>)

  • Prev by Date: Re: resignFirstResponder called immediately
  • Next by Date: Re: Implementing Licensing in C/ObjC/Cocoa (was: Re: [now OT] Licensing/Implementing in Cocoa/Obj-C - Interest in product?)
  • Previous by thread: Re: NSPanel as Sheet and controlling the run loop
  • Next by thread: Re: NSPanel as Sheet and controlling the run loop
  • Index(es):
    • Date
    • Thread