OutGauge Monitor Windows App example
I had a request for an example of Win Forms with OutGauge. This is a very simple project that illustrate how to quickly wire up output from OutGauge to UI. The only tricky bit for novices is the whole Invoke business. I.e. updates from outgauge come from it's listener thread. So you cannot use the event handler for outgauge to directly update your UI, or you'll get Cross-Thread exceptions. The solution is the common Invoke Required boilerplate:
private void outGaugeHandler_Updated(object sender, Gauge gauge)
{
// this code is required for Windows Forms, since our OutGauge update
// comes from another thread and we can only perform form updates on
// the UI thread
if (this.InvokeRequired)
{
BeginInvoke(new OutGaugeHandler.GaugeEvent(outGaugeHandler_Updated), sender, gauge);
return;
}
// now we update the form with the new data
// text boxes
timeTextBox.Text = gauge.Time.ToString();
carTextBox.Text = gauge.Car;
[...]
}
The Solution for this project is for Visual Studio 2005, but should work just fine in Visual C# Express. The zip of the project can be found here
Update: LFSLib.NET 0.14b has a bug where an OutGauge ID 0 zero would cause an exception. You can avoid this by using an OutGauge ID higher than 0 or wait for 0.15b to be released. Same thing is true for OutSim.