Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace multithreading in AppDelegate with NSTimer

  • Loading branch information...
commit b73c39b5eb39c02bbecad788e52b8c722d4d3132 1 parent 82192cf
Ole Begemann ole authored
2  TreeControllerTest/AppDelegate.h
View
@@ -14,4 +14,6 @@
@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, retain) IBOutlet NSTreeController *treeController;
@property (nonatomic, retain) NSArray *rootNodes;
+@property (nonatomic, retain) NSTimer *stressTestTimer;
+
@end
28 TreeControllerTest/AppDelegate.m
View
@@ -16,9 +16,12 @@ @implementation AppDelegate
@synthesize window = _window;
@synthesize treeController = _treeController;
@synthesize rootNodes = _rootNodes;
+@synthesize stressTestTimer = _stressTestTimer;
- (void)dealloc
{
+ [_stressTestTimer invalidate];
+ [_stressTestTimer release];
[_rootNodes release];
[_treeController release];
[super dealloc];
@@ -53,33 +56,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
// Try to provoke the error
#if STRESS_TEST
- [self performSelector:@selector(stressTest) withObject:nil afterDelay:5.0];
+ self.stressTestTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(replaceNode:) userInfo:nil repeats:YES];
#endif
}
-- (void) stressTest
-{
- [NSThread detachNewThreadSelector:@selector(_stressTest) toTarget:self withObject:nil];
-}
-
-
-- (void) _stressTest
-{
- [self performSelector:@selector(startReplacingNode) withObject:nil afterDelay:2.0];
-
- [[NSRunLoop currentRunLoop] run];
-}
-
-
-- (void) startReplacingNode
-{
- [self performSelectorOnMainThread:@selector(replaceNode) withObject:nil waitUntilDone:NO];
-
- [self performSelector:@selector(startReplacingNode) withObject:nil afterDelay:2.0];
-}
-
-- (void) replaceNode
+- (void)replaceNode:(NSTimer *)timer
{
static NSUInteger counter = 1;
Please sign in to comment.
Something went wrong with that request. Please try again.