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
|
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (SingleInstanceApplication.AlreadyExists &&
SingleInstanceApplication.NotifyExistingInstance(args))
return;
SingleInstanceApplication.Initialize();
SingleInstanceApplication.NewInstanceMessage += new NewInstanceMessageEventHandler(SingleInstanceApplication_NewInstanceMessage);
try
{
/* ... */
Application.Run(form);
}
finally
{
SingleInstanceApplication.Close();
}
}
static void SingleInstanceApplication_NewInstanceMessage(object sender, object message)
{
string[] args = null;
try
{
args = (string[])message;
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Erreur interne, impossible de récupérer les arguments d\'instance\n{0}",
ex), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (args != null && form != null)
{
/* maintenant tu peut traiter les arguments */
form.ProcessArguments(args);
form.Activate();
}
} |
Partager