I am building a system to record 6DOF information during an aerobatic flight. I grab data from a hardware set including an IMU, a GPS and a Baro altimeter and 20 to 30ms intervals. I attempted to use the WinForms Timer to schedule data recording using BW to allow me the collect the data in the DoWork method and then write the data to the WinForm in the WorkCompleted method. All this worked properly but the WinForms timer didn't provide the accuracy for scheduling the data properly. I did a test using a multimedia timer which provided the necessary update timing accuracy but when I used it to drive a BW the WorkCompleted method was no longer in the UI string and I get an error for trying to access a UI element from outside the UI string. I can make this work doing a BeginInvoke((MethodInvoker) delegate {all updates to UI elements in here}). What I would like to know if there is a way to force the WorkCompleted method back to the UI string. Also, not sure why changing the timer made the BW operation change and no longer have the WorkCompleted method in the UI string. The code for the program is below. The first set is my code and the second set it the C# code that implements the timer that I got off the internet. I'm not sure I used the
correctly but at least I tried. Appreciate any suggestions as I am still trying to figure out C# and the .net/Winforms environment.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace Simple_BW_Timing_with_Winforms
{
public partial class Form1 : Form
{
Stopwatch systemTimer;
long time1 = 0, time2 = 0;
public long timeBetweenCalls;
int count;
BackgroundWorker updateInfoBW;
public delegate void \_writeForm();
public readonly MicroLibrary.MicroTimer \_microTimer;
// public BackgroundWorker updateInfoBW;
public Form1()
{
updateInfoBW = new BackgroundWorker();
updateInfoBW.DoWork += updateInfoDoWork;
updateInfoBW.RunWorkerCompleted += updateInfoWorkCompleted;
InitializeComponent();
systemTimer = new Stopwatch();
systemTimer.Start();
\_microTimer = new MicroLibrary.MicroTimer();
\_microTimer.MicroTimerElapsed +=