[go: up one dir, main page]

Menu

[6396b6]: / Program.cs  Maximize  Restore  History

Download this file

106 lines (97 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
/***********************************************************************************
This file is part of Clock Alert.
Clock Alert is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as published by
the Free Software Foundation.
Clock Alert is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clock Alert. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************************/
using System;
using System.Windows.Forms;
using System.Threading;
//using System.Diagnostics;
namespace Clock_Alert
{
static class Program
{
/// <summary>
/// The named mutual exclusion object that is
/// owned by the first instance of the app that is created.
/// It holds the first application instance (process)
/// and prevents the app from running in a new instace (process).
/// </summary>
static Mutex mutExcl;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool firstInstance = false;
/*
* New mutual exclusion object is created with
* the current thread as owner.
* It is given the same name as the app.
* If the object was succesfully created with the current thread as owner,
* firstInstance variable is set to true.
*/
mutExcl = new Mutex(true, Application.ProductName.ToString(), out firstInstance);
/*
* If the Mutual exclusion object was succesfully created
* then we start the application
* If not
* It means that the mutex object is owned by the first instance
* and a second instance trying to start the application.
* So we show a message that the application is already running.
*/
if(firstInstance)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (Startup app = new Startup())
{
app.startApp();
Application.Run();
}
}
else
{
System.Windows.Forms.MessageBox.Show("Clock Alert is already running!", "Clock Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/*
* Comenting this code because it sometimes prevent
* the app from restarting when the settings are
* changed by the user. and the app closes.
Process currentProcess = Process.GetCurrentProcess();
Process[] runningProcess = Process.GetProcessesByName(currentProcess.ProcessName);
int numberOfProcess = runningProcess.Length;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
if (numberOfProcess == 1)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (Startup app = new Startup())
{
app.startApp();
Application.Run();
}
}
else
{
System.Windows.Forms.MessageBox.Show("I'm here already!", "Clock Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
}*/
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = (Exception)e.ExceptionObject;
CrashReporterUI reportWindow = new CrashReporterUI(ex);
reportWindow.ShowDialog();
Application.Exit();
}
}
}