• 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
some NSThread questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

some NSThread questions


  • Subject: some NSThread questions
  • From: Koen van der Drift <email@hidden>
  • Date: Mon, 31 May 2004 18:32:07 -0400

Hi,

I just started learning about using thread, and have some questions.

I want to control the start and end of an NSThread by a start and stop button. When the user pushes the start button, I want to disable it to prevent a new NSThread to start. Disabling the button works fine, but where do I put the call to enable it back when the thread is finished?

-(IBAction)start:(id)sender
{
[sender setEnabled:NO];

// start a new thread
[NSThread detachNewThreadSelector: @selector(run:)
toTarget: self
withObject: nil];

}


Also, when I use the stop button, the thread apparently stops (I get no more output from the calculation), but the stop button remains blue, and after a while I get a spinning beachball. It could well be related to somthing in the calculation, but just to be sure, this is what I use to stop the thread:

-(IBAction)stop:(id)sender
{
[NSThread exit];

// myPrintf("Calculation was interrupted by the user");
}



Finally, I read something about the AppKit being thread unsafe. During the calculation in the second thread many results are displayed in an NSTextView, using calls like:

[theResultsTextView replaceCharactersInRange:
NSMakeRange([[theResultsTextView string] length], 0) withString:s];


Do I need to sandwich this code with a lock?


thanks,

- Koen.
_______________________________________________
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: some NSThread questions
      • From: Dustin Voss <email@hidden>
  • Prev by Date: Re: Subclassing an object's creation method (NSBezierPath's +bezierPath)
  • Next by Date: Re: How to include InternetConfig.h
  • Previous by thread: Re: How to include InternetConfig.h
  • Next by thread: Re: some NSThread questions
  • Index(es):
    • Date
    • Thread