Esempio n. 1
0
        //Add this method override
        protected override void OnStartup(StartupEventArgs e)
        {
            m_Mutex = new Mutex(true, "HomeGenieManagerMutex", out createdNew);
            //e.Args is the string[] of command line argruments
            //
            upnpService                 = new Dictionary <string, UPnPDevice>();
            upnpControl                 = new UPnPControlPoint();
            upnpControl.OnSearch       += upnpcontrol_OnSearch;
            upnpControl.OnCreateDevice += upnpcontrol_OnCreateDevice;
            upnpControl.FindDeviceAsync("urn:schemas-upnp-org:device:HomeAutomationServer:1");
            //
            Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose;
            var myDialogWindow = new LoadingDialog();

            myDialogWindow.Show();
            //
            Task loader = new Task(() =>
            {
                int t = 0;
                while (t < 10)
                {
                    if (upnpService.Count > 0)
                    {
                        Thread.Sleep(2000);
                        for (int s = 0; s < UPnPDevices.Count; s++)
                        {
                            var dev = UPnPDevices.ElementAt(s).Value;
                            if (dev.StandardDeviceType == "HomeAutomationServer")
                            {
                                System.Diagnostics.Process.Start(dev.PresentationURL);
                                t = 10;
                                break;
                            }
                        }
                    }
                    t++;
                    Thread.Sleep(1000);
                }
                //
                Thread.Sleep(2000);
                //
                myDialogWindow.Dispatcher.BeginInvoke(new Action(() =>
                {
                    if (!createdNew)
                    {
                        myDialogWindow.Close();
                        Application.Current.Shutdown();
                    }
                    else
                    {
                        var window = new MainWindow();
                        window.Show();
                        myDialogWindow.Close();
                    }
                }), null);
            });

            loader.Start();
        }
Esempio n. 2
0
 //Add this method override
 protected override void OnStartup(StartupEventArgs e)
 {
     m_Mutex = new Mutex(true, "HomeGenieManagerMutex", out createdNew);
     //e.Args is the string[] of command line argruments
     //
     upnpService = new Dictionary<string, UPnPDevice>();
     upnpControl = new UPnPControlPoint();
     upnpControl.OnSearch += upnpcontrol_OnSearch;
     upnpControl.OnCreateDevice += upnpcontrol_OnCreateDevice;
     upnpControl.FindDeviceAsync("urn:schemas-upnp-org:device:HomeAutomationServer:1");
     //
     Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose;
     var myDialogWindow = new LoadingDialog();
     myDialogWindow.Show();
     //
     Task loader = new Task(() =>
     {
         int t = 0;
         while (t < 10)
         {
             if (upnpService.Count > 0)
             {
                 Thread.Sleep(2000);
                 for (int s = 0; s < UPnPDevices.Count; s++)
                 {
                     var dev = UPnPDevices.ElementAt(s).Value;
                     if (dev.StandardDeviceType == "HomeAutomationServer")
                     {
                         System.Diagnostics.Process.Start(dev.PresentationURL);
                         t = 10;
                         break;
                     }
                 }
             }
             t++;
             Thread.Sleep(1000);
         }
         //
         Thread.Sleep(2000);
         //
         myDialogWindow.Dispatcher.BeginInvoke(new Action(() =>
         {
             if (!createdNew)
             {
                 myDialogWindow.Close();
                 Application.Current.Shutdown();
             }
             else
             {
                 var window = new MainWindow();
                 window.Show();
                 myDialogWindow.Close();
             }
         }), null);
     });
     loader.Start();
 }