Files
Analog_System_Monitor/analog_system_monitor_dotnet/TrayApp.cs

42 lines
1.0 KiB
C#

#nullable enable
using System;
using System.Drawing;
using System.Windows.Forms;
public class TrayApp : ApplicationContext
{
private NotifyIcon trayIcon;
private Telemetry telemetry;
public TrayApp()
{
telemetry = new Telemetry();
telemetry.Initialize();
trayIcon = new NotifyIcon()
{
Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath),
Visible = true,
Text = "Telemetry Running"
};
var menu = new ContextMenuStrip();
menu.Items.Add("Exit", null, OnExit);
trayIcon.ContextMenuStrip = menu;
// Start telemetry loop
var timer = new System.Windows.Forms.Timer();
timer.Interval = 1000;
timer.Tick += (s, e) => telemetry.UpdateAndSend();
timer.Start();
}
private void OnExit(object? sender, EventArgs e)
{
telemetry.Dispose();
trayIcon.Visible = false;
Application.Exit();
}
}