Problem using NSTimer in MonoTouch.NET stream

I have a problem using NSTimer in MonoTouch. To start, I ran NSTimer in my main thread, which worked. However, I have moved the timer to a separate thread, and I never get a callback. I suppose this is because my .NET-style thread is not a startup loop, but I'm completely new to MonoTouch / iOS, so I'm not sure.

I pulled the code into a test project and had the same problem. This code does not work:

var thread=new Thread(StartTimer as ThreadStart);
thread.Start();

[Export("StartTimer")]
void StartTimer()
{
    using(var pool = new NSAutoreleasePool())
    {
         timer=NSTimer.CreateRepeatingScheduledTimer(2,delegate { Twitch() } );
         Thread.Sleep(1000000);    // do I have to yield here somehow?
    }
}

void Twitch()
{
    Debug.WriteLine("Twitch");
}
+5
source share
1 answer

, , , , runloop. :

NSRunLoop.Current.Run ();

Thread.Sleep (1000000);
+6

All Articles