Пример #1
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try {
                SirenEvents = new SirenEvents(eventsFilePath);
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
                Application.Exit();
            }

            bool isFirstInstance;
            // Please use a unique name for the mutex to prevent conflicts with other programs
            string appName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

            using (Mutex mtx = new Mutex(true, appName, out isFirstInstance)) {
                if (isFirstInstance)
                {
                    NotificationIcon notificationIcon = new NotificationIcon();
                    notificationIcon.notifyIcon.Visible = true;
                    timer       = new System.Windows.Forms.Timer();
                    timer.Tick += delegate(object sender, EventArgs e)
                    {
                        SirenEvent se = SirenEvents.FindExpired();
                        if (null != se)
                        {
                            ShowSirenEventsForm(true, se.EventText);
                        }
                    };
                    timer.Interval = 2000;
                    timer.Enabled  = true;
                    timer.Start();
                    Application.Run();
                    notificationIcon.notifyIcon.Dispose();
                }
                else
                {
                    // The application is already running
                    MessageBox.Show(
                        "Application already running, look at system tray icon",
                        "Application already running",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Asterisk
                        );
                }
            } // releases the Mutex
        }
Пример #2
0
        void SirenEventsFormLoad(object sender, EventArgs e)
        {
            Int32 currentTimestamp = SirenEvent.GetCurretnTimestamp();

            sirenEvents = NotificationIcon.SirenEvents;

            listView1.ListViewItemSorter =
                new ListViewItemComparer(
                    (-1 != sortColumn ? sortColumn : 0),
                    listView1.Sorting
                    );

            foreach (SirenEvent se in sirenEvents)
            {
                AddListItem(se);
            }
        }