SafeDispatch/SDRgateway/Program.cs

115 lines
4.3 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using SafeMobileLib;
using System.IO;
using SafeMobileLib.Helpers;
using Microsoft.VisualBasic.ApplicationServices;
using System.Collections.ObjectModel;
namespace SDRgateway
{
static class Program
{
public static SafeMobileLib.InterthreadMessageQueue<msgCell> gpsQueue = new SafeMobileLib.InterthreadMessageQueue<msgCell>();
public static SafeMobileLib.InterthreadMessageQueue<msgCell> smsINQueue = new SafeMobileLib.InterthreadMessageQueue<msgCell>();
public static SafeMobileLib.InterthreadMessageQueue<msgCell> smsOutQueue = new SafeMobileLib.InterthreadMessageQueue<msgCell>();
public static SafeMobileLib.InterthreadMessageQueue<msgCell> eventQueue = new SafeMobileLib.InterthreadMessageQueue<msgCell>();
public static Config cfg;
static String filename = "";
static void Main(string[] args)
{
cfg = new Config();
//TestClass.TestMSG("001800061894989a670a70ff0000540201284841f9a62b086020");
//TestClass.TestMSG("001800061894989a670a70ff00005402012844d9f9a782112000");
//Console.ReadKey();
//LIP lip = new LIP();
//lip.decoder("30d3c8667e4607ffe810");
Console.Title = "SDRGatewayConsole";
// parse the command line args
CommandLineHelper clh = new CommandLineHelper(args, Console.Title);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (!AppDomain.CurrentDomain.FriendlyName.EndsWith("vshost.exe"))
{
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
// Set the unhandled exception mode to force all Windows Forms errors
// to go through our handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new System.UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
SingleInstanceController controller = new SingleInstanceController();
controller.Run(args);
}
public class SingleInstanceController : WindowsFormsApplicationBase
{
public static ReadOnlyCollection<string> CommandLineArgs = null;
public SingleInstanceController()
{
IsSingleInstance = true;
Startup += SingleInstanceController_Startup;
StartupNextInstance += this_StartupNextInstance;
}
void SingleInstanceController_Startup(object sender, StartupEventArgs e)
{
}
void this_StartupNextInstance(object sender, StartupNextInstanceEventArgs e)
{
if (MainForm.WindowState == FormWindowState.Minimized)
{
MainForm.Show();
MainForm.ShowInTaskbar = true;
MainForm.WindowState = FormWindowState.Normal;
// bring to front
MainForm.Activate();
}
}
protected override void OnCreateMainForm()
{
MainForm = new MainForm();
}
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message, "ThreadException SDRgateway.Please restart the application.");
Utils.WriteEventLog("SDRgateway", "ThreadException : " + e.Exception.ToString(), EventLogEntryType.Error, 401);
// here you can log the exception ...
}
static void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
{
MessageBox.Show((e.ExceptionObject as Exception).Message, "Unhandled UI Exception SDRgateway.Please restart the application.");
// here you can log the exception ...
Utils.WriteEventLog("SDRgateway", "ThreadException : " + e.ToString(), EventLogEntryType.Error, 402);
}
}
}