Esempio n. 1
0
        private void CreateNotifyIcon()
        {
            if (notifyIcon != null)
            {
                return;
            }
            Thread thread = new Thread(() => {
                // We need to make a new thread because we have to guarantee
                // contextMenuNotifyIcon is only accessed from a single thread.
                // InstanceManager could call us from many different threads.
                lock (dicNotifyIcon) {
                    if (notifyIcon != null)
                    {
                        return;                    // double check to prevent race conditions
                    }
                    icoNotify                          = QTUtility.GetIcon(string.Empty, false);
                    contextMenuNotifyIcon              = new ContextMenuStripEx(null, false);
                    contextMenuNotifyIcon.ImageList    = QTUtility.ImageListGlobal;
                    contextMenuNotifyIcon.ItemClicked += contextMenuNotifyIcon_ItemClicked;
                    contextMenuNotifyIcon.EnsureHandleCreated();
                    notifyIcon = new NotifyIcon {
                        Icon             = icoNotify,
                        ContextMenuStrip = contextMenuNotifyIcon,
                        Visible          = false
                    };
                    notifyIcon.MouseDoubleClick += notifyIcon_MouseDoubleClick;
                    Monitor.Pulse(dicNotifyIcon);
                }
                Application.Run();
            })
            {
                IsBackground = true
            };

            lock (dicNotifyIcon) {
                thread.Start();
                Monitor.Wait(dicNotifyIcon);
            }
        }
Esempio n. 2
0
 private void CreateNotifyIcon()
 {
     if(notifyIcon != null) return;
     Thread thread = new Thread(() => {
         // We need to make a new thread because we have to guarantee
         // contextMenuNotifyIcon is only accessed from a single thread.
         // InstanceManager could call us from many different threads.
         lock(dicNotifyIcon) {
             if(notifyIcon != null) return; // double check to prevent race conditions
             icoNotify = QTUtility.GetIcon(string.Empty, false);
             contextMenuNotifyIcon = new ContextMenuStripEx(null, false);
             contextMenuNotifyIcon.ImageList = QTUtility.ImageListGlobal;
             contextMenuNotifyIcon.ItemClicked += contextMenuNotifyIcon_ItemClicked;
             contextMenuNotifyIcon.EnsureHandleCreated();
             notifyIcon = new NotifyIcon {
                 Icon = icoNotify,
                 ContextMenuStrip = contextMenuNotifyIcon,
                 Visible = false
             };
             notifyIcon.MouseDoubleClick += notifyIcon_MouseDoubleClick;
             Monitor.Pulse(dicNotifyIcon);
         }
         Application.Run();
     }) { IsBackground = true };
     lock(dicNotifyIcon) {
         thread.Start();
         Monitor.Wait(dicNotifyIcon);
     }
 }