Re: NSThread Question
Re: NSThread Question
- Subject: Re: NSThread Question
- From: Drew McCormack <email@hidden>
- Date: Tue, 23 Apr 2002 20:19:39 +0200
On Tuesday, April 23, 2002, at 07:45 PM, Lorenzo Puleo wrote:
I should have to run/stop a cycle using the same button.
I would like to break the loop at any time pressing the same button.
But when I press the button to start the loop, I can't press again the
button to stop the loop. I have to wait the loop ends...
Also, the button still appears blue-pressed...
I understand I have to use NSThread, but I don't understand how I can do
this using my current routine since NSThread requires methods (+) which
don't allow to manipulate variable instances and factories within
theirselves as, instead, I have to do.
Any ideas would be greatly appreciated as I am relatively
new to Cocoa. Thanks.
I found Threadworker was a good way to break off a thread easily. It
also has good example code for you to look at.
Check it out:
http://iharder.sourceforge.net/macosx/threadworker/
By the way, I think you are wrong about not being able to access
instance variables. When you call the NSThread
factory method, you pass a target in, which is the object for which the
thread will execute a method. You can of course make the target "self"
if you want to run your loop and be able to access the ivar. You may
also need to use NSLock to prevent synchronization problems though (see
docs).
Drew
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ...
Dr. Drew McCormack
Trade Strategist (www.trade-strategist.com)
Trading simulation software for Mac OS X
_______________________________________________
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.