This is SimpleTest.m in view mode; [Download] [Up]
#import "SimpleTest.h" #import <threadkit/threadkit.h> @implementation SimpleTest - dangerTest:sender { [ [ TKThread alloc ] initFor: self perform: @selector ( dangerousAction ) ] ; return self ; } // Note: // // This code isn't "dangerous" in the sense that the protection // was designed for. This behaviour could normally be implemented // here with no special protection at all. It's just a test of the // calls themselves (they should fail if they can't stop all active // threads ... if one is suspended, for example). // // A more suitable example would be to link in new Objective-C // classes. Note also that spawning another thread is the // ONLY way to do this reliably. See the TKThread class // documentation for an explanation. - dangerousAction { if ( [ TKThread startDangerousAction: 500 ] ) { [ window moveTo: 10 : 500 ] ; [ window moveTo: 500 : 10 ] ; [ window moveTo: 800 : 140 ] ; [ window moveTo: 131 : 449 ] ; [ textField setStringValue: "Successfully Completed." ] ; [ TKThread endDangerousAction ] ; } else { [ NXApp threadLock ] ; [ textField setStringValue: "Failed." ] ; [ NXApp threadUnlock ] ; } return self ; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.