public FormMain(HostDetectorSettings settings, HostDetector detector)
        {
            InitializeComponent();
            this.settings = settings;


            detector.NotifyPresent += InvokeNotifyPresent;
            Monitor.Exit(detector); // Allow detector thread to proceed.
            UnmanagedMemoryStream audioStream;

            switch (settings.soundId)
            {
            case 1:
                audioStream = Properties.Resources.MainSound1;
                break;

            case 2:
                audioStream = Properties.Resources.MainSound2;
                break;

            default:
                audioStream = Properties.Resources.MainSound1;
                break;
            }
            soundPlayer = new SoundPlayer(audioStream);
        }
Beispiel #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool  createdNew = false;
            Mutex mutex      = null;

            try
            {
                mutex = new Mutex(true, "HostDetector", out createdNew);
            }
            catch {}
            if (mutex == null || !createdNew)
            {
                MessageBox.Show("HostDetector is already running", "HostDetector could not be started", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
            }
            else
            {
                try
                {
                    HostDetectorSettings settings = new HostDetectorSettings();
                    settings.InitializeFromConfigFile();
                    detector = new HostDetector(settings);
                    Thread newThread = new Thread(RunDetector);
                    newThread.IsBackground = true;
                    Monitor.Enter(detector); // GUI thread needs to set up callbacks
                    newThread.Start();
                    Application.Run(new FormMain(settings, detector));
                }
                finally
                {
                    mutex.Close();
                }
            }
        }