/// <summary> /// Close when all menus are being closed. /// </summary> protected void OnCloseAll() { if (CloseAll != null) { CloseAll.Invoke(); } }
/// <summary> /// method to close the server by stops the server from listening for new clients, /// and commanding the open handlers to close. /// </summary> public void Close() { listener.Stop(); // invoke close all directories CommandRecieved Event CloseAll?.Invoke(this, null); // wait for all handlers to close while ((CloseAll != null) && (CloseAll.GetInvocationList().Length > 0)) { System.Threading.Thread.Sleep(1000); } m_logging.Log("Server closed", MessageTypeEnum.INFO); }
/// <summary> /// Invokes the Click and CloseAll events, if menu item doesn't have a /// popup menu. /// </summary> internal void InvokeClick() { // Check that there are no children if (this.numMenuItems == 0 && this.isEnabled) { if (Click != null) { Click.Invoke(this); } if (CloseAll != null) { CloseAll.Invoke(); } } }
public MainNotifyIcon() { icon = new NotifyIcon(); icon.BalloonTipTitle = Resources.AppName; icon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); var strip = new ContextMenuStrip(); ToolStripItem closeAll = new ToolStripMenuItem(Resources.NotifyIcon_CloseAllWindows); closeAll.Click += (s, e) => CloseAll?.Invoke(s, e); strip.Items.Add(closeAll); ToolStripItem quit = new ToolStripMenuItem(Resources.NotifyIcon_Quit); quit.Click += (s, e) => Quit?.Invoke(s, e); strip.Items.Add(quit); strip.Items.Add(new ToolStripSeparator()); icon.ContextMenuStrip = strip; icon.Visible = true; icon.Click += (s, e) => { /* * For some reason there are no public methods on NotifyIcon or ContextMenuStrip * to show the menu "for the taskbar" with the same behavior as a right click. * This private method does the job and it's pretty safe to expect it to exist since it's * been around forever and win forms is already old and not going to change. * We check for null anyway just in case. */ typeof(NotifyIcon) .GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic) ?.Invoke(icon, null); }; }
/// <summary> /// stop all listeners /// </summary> public void StopListening() { CloseAll?.Invoke(this, null); Logger.Log("Stop listening to all folders", MessageTypeEnum.L_INFO); }