SafeDispatch/GatewayTetraVoice/Program.cs

100 lines
3.5 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.IO;
using smutils = SafeMobileLib.Utils;
using System.Diagnostics;
using Microsoft.VisualBasic.ApplicationServices;
using System.Collections.ObjectModel;
using SafeMobileLib.Helpers;
using Tetra_GW.Helpers;
namespace Tetra_GW
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static MainForm MainWindow = null;
static String filename = "";
static void Main(string[] args)
{
Console.Title = "Tetra_GWConsole";
// parse the command line args
CommandLineHelper clh = new CommandLineHelper(args, Console.Title);
// load the configuration for the gateway
ConfigHelper.LoadConfig();
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 TetraGateway. Please restart the application.");
SafeMobileLib.Utils.WriteEventLog("TetraGateway", "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 TetraGateway. Please restart the application.");
// here you can log the exception ...
SafeMobileLib.Utils.WriteEventLog("TetraGateway", "ThreadException : " + e.ToString(), EventLogEntryType.Error, 402);
}
}
}