public void SendMessage(DownloadMessage msg)
 {
     if (tracker == null)
     {
         // Attempt to create a tracker
         tracker = new SingleInstanceTracker("SingleInstanceSample", new SingleInstanceEnforcerRetriever(GetSingleInstanceEnforcer));
     }
     if (msg != null)
     {
         var json = JsonConvert.SerializeObject(msg);
         tracker.SendMessageToFirstInstance(json);
     }
 }
        public void Start(string[] args, DownloadMessage msg)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                // Attempt to create a tracker
                tracker = new SingleInstanceTracker("SingleInstanceSample", new SingleInstanceEnforcerRetriever(GetSingleInstanceEnforcer));

                // If this is the first instance of the application, run the main form
                if (tracker.IsFirstInstance)
                {
                    try
                    {
                        DownloadCenterForm form = (DownloadCenterForm)tracker.Enforcer;

                        //form.downloadList1.AddDownloadURLs(ResourceLocation.FromURLArray(args), 1, null, 0);

                        //if (Array.IndexOf<string>(args, "/as") >= 0)
                        //{
                        //    form.WindowState = FormWindowState.Minimized;
                        //}

                        //form.Load += delegate(object sender, EventArgs e)
                        //    {

                        //        if (form.WindowState == FormWindowState.Minimized)
                        //        {
                        //        }

                        //        if (args.Length > 0)
                        //        {
                        //        }
                        //    };

                        form.FormClosing += delegate(object sender, FormClosingEventArgs e)
                        {
                            Dispose();
                        };
                        Application.Run(form);
                    }
                    finally
                    {
                        Dispose();
                    }
                }
                else if (Properties.Settings.Default.ChromeIntegration)
                {
                    if (msg != null)
                    {
                        var json = JsonConvert.SerializeObject(msg);
                        tracker.SendMessageToFirstInstance(json);
                    }
                }
            }
            catch
            {
                return;
            }
            finally
            {
                if (tracker != null)
                {
                    tracker.Dispose();
                }
            }
        }