I am new to iOS programming. I am using the following code ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property dispatch_queue_t background;
- (IBAction)stop_resume:(UIBarButtonItem *)sender;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize background;
- (void)viewDidLoad
{
[super viewDidLoad];
background = dispatch_queue_create("background", NULL);
dispatch_async(background, ^{
for(int i=0; ; i++)
{
NSLog(@"Number is %d\n", i);
}
});
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)stop_resume:(UIBarButtonItem *)sender
{
dispatch_suspend(background);
}
@end
When i press the button the background thread does not get suspended, the loop continues to run.