Using NSTimer to call SetNeedsDisplay in Xamarin for iOS
Asked Answered
A

1

6

I have a UIView that takes data (thats changing) from a buffer and plots it. I want the screen udpated at 10Hz. The UIView is called pane, and this is how i'm invoking it inside the ViewController:

        //create graphics to display data
        GraphPane pane = new GraphPane ();
        pane.Frame = UIScreen.MainScreen.Bounds;
        Add (pane); 

        //setup timer to update pane
        NSTimer timer = NSTimer.CreateRepeatingTimer (0.1, delegate {pane.SetNeedsDisplay ();});

This isn't working (Pane.Draw is never called), and I've not found a good example of how to do this. Any suggestions are appreciated.

Anabolite answered 14/6, 2013 at 0:43 Comment(2)
Is timer deallocated when it goes out of scope?Hole
I actually have timer defined as a class variable so it shouldn't.Anabolite
A
11
        timer = NSTimer.CreateRepeatingScheduledTimer (TimeSpan.FromSeconds (0.1), delegate {
            pane.SetNeedsDisplay ();
        });

fixed my issue.

Anabolite answered 14/6, 2013 at 2:16 Comment(1)
The change was from CreateReapeatingTimer to CreateRepeatingScheduledTimer - seems it isn't scheduled by default.Anabolite

© 2022 - 2024 — McMap. All rights reserved.