Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PerformSelector Monotouch Threading

Using this statement calls the selector immediately instead of 6 seconds from now.

this.PerformSelector(myStartWaitForSoundSelector, null, 6.0f);

Does anyone know how to get this to work with a delay?

I am using thread.Sleep(6000)in the function that gets called, but the entire application locks up for six seconds.

Thanks.

like image 219
Bryan Avatar asked Dec 21 '09 20:12

Bryan


1 Answers

You can use an NSTimer:

NSTimer.CreateScheduledTimer(new TimeSpan(0, 0, 6),
                    delegate { Console.WriteLine("teste"); });

That will cause the code inside the delegate to run after 6 seconds, without blocking the main application thread.

like image 168
Eduardo Scoz Avatar answered Oct 26 '22 07:10

Eduardo Scoz