public MainWindow() { InitializeComponent(); mainThreadId_ = Thread.CurrentThread.ManagedThreadId; ecgGenerator_ = new DataGen.Electrocardiogram(); #if USE_RENDERING_CALLBACK CompositionTarget.Rendering += CompositionTarget_Rendering; #elif USE_DISPATCHERTIMER timer_ = new DispatcherTimer(); timer_.Tick += Timer__Tick; timer_.Interval = new TimeSpan(0, 0, 0, 0, 100); timer_.Start(); #elif USE_MMTIMER timer_ = new MMTimer(Timer__Tick) { Interval = 50, }; timer_.Start(); #elif USE_TIMERQUEUETIMER cancellationTokenSource_ = new CancellationTokenSource(); timer_ = new TimerQueueTimer(); waitOrTimerDelegate_ = new WaitOrTimerDelegate(Timer__Tick); // Avoid GC timer_.Create(1000, 50, waitOrTimerDelegate_); #endif stopwatch_ = Stopwatch.StartNew(); }
public Telemetry(IPluginTelemetryProvider provider, Process simulatorProcess) { Provider = provider; // Initialize memory objects var mem = new MemoryReader(); mem.Open(simulatorProcess); Memory = new MemoryProvider(mem); // Initialize telemetry provider; this class gives us the address layout to read. Memory.Scanner.Enable(); Provider.Initialize(Memory); Memory.Scanner.Disable(); // Start outside-world telemetry objects Session = new TelemetrySession(); Simulator = new TelemetryGame(); Acquisition = new TelemetryAcquisition(); Support = new TelemetrySupport(); // Start 40Hz clock signal (25ms) Clock = new MMTimer(25); Clock.Tick += (o, s) => GlobalEvents.Fire(new TelemetryRefresh(this), true); Clock.Start(); // Hook both events together: GlobalEvents.Hook <TelemetryRefresh>(Update, true); }
static void Main(string[] args) { var stopwatch = Stopwatch.StartNew(); int count = 0; const int MaxCount = 20; var timer = new Timer( _ => { Console.WriteLine("Elapsed ms: {0}", stopwatch.ElapsedMilliseconds); Interlocked.Increment(ref count); }, null, 1000, 100); while (true) { if (Thread.VolatileRead(ref count) >= MaxCount) { timer.Dispose(); break; } } Console.WriteLine("---------- MMTimer ----------"); count = 0; stopwatch.Restart(); var mmTimer = new MMTimer( _ => { Console.WriteLine("Elapsed ms: {0}", stopwatch.ElapsedMilliseconds); Interlocked.Increment(ref count); } ) { Interval = 100 }; mmTimer.Start(); while (true) { if (Thread.VolatileRead(ref count) >= MaxCount) { mmTimer.Stop(); break; } } Util.Pause(); }
public void Connect(object target) { generateData = new MMTimer(10); generateData.Tick += GenerateDataElapse; generateData.Start(); IsConnected = true; if (Connected != null) { Connected(this, new EventArgs()); } }
public MainWindow() { InitializeComponent(); #if USE_MMTIMER timer_ = new MMTimer(Tick, null, null, true) { Interval = 200, }; timer_.Start(); #elif USE_DISPATCHERTIMER timer_ = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(50), }; timer_.Tick += Timer__Tick; timer_.Start(); #else CompositionTarget.Rendering += CompositionTarget_Rendering; #endif }