public TrayIcon() { // Sample Definition of a Task for the Worker to Perform Worker = new TrayWorker( delegate { MessageBox.Show($"Hi! I am a {nameof(TrayWorker)} called {nameof(Worker)}!", "Example Worker"); }); #region Create Context Menu var menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { #region Sample Items new ToolStripMenuItem( "Re-Run Worker", image: Resources.loop_circular_2x, onClick: delegate { if (!Worker.IsBusy) { Worker.RunWorkerAsync(); } }), new ToolStripSeparator(), // Recommended Exit Procedure for Graceful Close new ToolStripMenuItem( "Exit", image: Resources.account_logout_2x, onClick: delegate { if (Worker.IsBusy) { Worker.Finished += delegate { Application.Exit(); }; Worker.CancelRequested = true; } else { Application.Exit(); } }) #endregion }); #endregion #region Create NotifyIcon Icon = new NotifyIcon { Icon = System.Drawing.Icon.FromHandle(Resources.bolt_2x.GetHicon()), ContextMenuStrip = menu, Visible = true }; #endregion Worker.RunWorkerAsync(); }
static void Main(string[] args) { var contextMenu = new TrayMenu(); var pluginManager = new PluginManager(contextMenu); pluginManager.LoadPlugins(); var worker = new TrayWorker(contextMenu); Application.Run(); }