As long as the application is running i need to change the status icon once in 2 sec., i think in my case i have to do it in separate thread.
This is my scenario.
I have 2 NSObject initialised in my MainMenu.nib. One of them is main controller AppDelegate and other one ChangeStatusBar to change the icon. I have an IBOutlet in my AppDeligate pointing to ChangeStatusBar object. From AppDeligate i am calling one method of ChangeStatusBar which uses performSelectorInBackground with run loop at achieve this. Which is not working. My method to change icon is getting called but image is not changing during AppDeligate wait. My Appdeligate can go on unconditional wait, even in such case i want StatusItem image changing. Ex: say you have scanf in AppDeligate or you are calling an API that can return after sum time. Thanks in Advance. Here is my code.
// AppDelegate.m
-(void)applicationDidFinishLaunching:(NSNotification*)notification
{
[statusItem initStatusItem:true]; //StatusItem is the IBOutlet to ChangeStatusBar object
}
//ChangeStatusBar.m
-(void)initStatusItem:(BOOL) flag
{
statusItem = [[[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength]retain] ;
[statusItem setMenu:statusMenu];
[statusItem setImage:[NSImage imageNamed:@"lk0.png"]];
[self performSelectorInBackground:@selector(timerStart) withObject:nil];
}
-(void) timerStart
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
[[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(changeImages)
userInfo:nil repeats:YES] retain];
[runLoop run];
[pool release];
}
///Change image here
-(void)changeImages
{
[statusItem setImage:[NSImage imageNamed:[NSString stringWithFormat:@"lk%d.png",NoImages]]];`
}