I'm lazy, I hate typing more than I have to. As a result, I have adapted a method that avoids having to add 'static' to every function and variable, and follows the Arduino model a little closer. I insert the following code in just about every project I start.
I hope this prevents some carpel tunnel syndrome for someone;
namespace Junk2 { public class Program { bool instanceDone = false; DateTime lastTick; EncodedMotor M0; public static void Main() { var p = new Program(); p.Setup(); while (!p.instanceDone) p.Loop(); } void Setup() { // do initialize things here // pwm, phA, phB, reversed M0 = new EncodedMotor(PWMChannels.PWM_PIN_D5, Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D10, true); lastTick = DateTime.Now; } void Loop() { DateTime thisTick = DateTime.Now; TimeSpan dt = thisTick - lastTick; //.... more stuff Thread.Sleep(1000 / 20); // update N times per sec lastTick = thisTick; } } }