Last active
February 26, 2021 06:47
Tray App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using testTray.Properties; | |
static class Program | |
{ | |
/// <summary> | |
/// The main entry point for the application. | |
/// </summary> | |
[STAThread] | |
static void Main() | |
{ | |
Application.EnableVisualStyles(); | |
Application.SetCompatibleTextRenderingDefault(false); | |
Application.Run(new TrayApp()); | |
} | |
} | |
class TrayApp : ApplicationContext | |
{ | |
private NotifyIcon trayIcon; | |
public TrayApp() | |
{ | |
// Initialize Tray Icon | |
trayIcon = new NotifyIcon() | |
{ | |
Icon = Resources.paper_write_folio_icon_179376, | |
ContextMenu = new ContextMenu(new MenuItem[] { | |
new MenuItem("Exit", Exit) | |
}), | |
Visible = true | |
}; | |
MyHardwareController controller = new MyHardwareController(); | |
} | |
void Exit(object sender, EventArgs e) | |
{ | |
// Hide tray icon, otherwise it will remain shown until user mouses over it | |
trayIcon.Visible = false; | |
Application.Exit(); | |
} | |
} | |
class MyHardwareController | |
{ | |
public MyHardwareController() { | |
//Simulating a hardware event | |
//The thread creation is controlled by library | |
Thread thread1 = new Thread(ThreadWork.DoWork); | |
thread1.Start(); | |
} | |
} | |
public class ThreadWork | |
{ | |
public static void DoWork() | |
{ | |
Thread.Sleep(5000); | |
Clipboard.SetText("This is a testing text"); | |
SendKeys.SendWait("^(v)"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment