• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
To run a block of code at every 1 second
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

To run a block of code at every 1 second


  • Subject: To run a block of code at every 1 second
  • From: Stuart Malin <email@hidden>
  • Date: Tue, 3 Mar 2009 07:36:40 -1000


On Mar 3, 2009, at 7:24 AM, email@hidden wrote:

the following method is running in a separate thread:

- (void)myFucntion
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	for (;;)// for loop starts here and is very quick, 100s of iterations
per second
	{

		{
			// this block of code needs to be run at around 1 second interval
			// code here
			[appController
performSelectorOnMainThread:@selector(updateProgress:) withObject:data
waitUntilDone:YES];
		}
		// other loop code here
	}
	[loop release];
}


Not quite sure if I understand exactly your need, but perhaps this might be helpful:

The following will delay for one second by sleeping the thread. Perhaps you could set the future date at the start of the loop block, and at the end, if the date is still in the future, sleep the thread.

	NSDate *future = [NSDate dateWithTimeIntervalSinceNow: 1.0f ];
	[NSThread sleepUntilDate:future];
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: To run a block of code at every 1 second
  • Next by Date: Re: To run a block of code at every 1 second
  • Previous by thread: Re: To run a block of code at every 1 second
  • Next by thread: NSCell highlighting for keyboard equivalents
  • Index(es):
    • Date
    • Thread