Running ThreadSelector Monotouch Threading

Using this operator calls the selector immediately, and not after 6 seconds.

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

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

I use thread.Sleep(6000)in the called function, but the whole application is blocked for six seconds.

Thanks.

+5
source share
1 answer

You can use NSTimer:

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

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

+8
source

All Articles