Skip to content

Instantly share code, notes, and snippets.

@jki21
Last active February 26, 2021 06:47
Tray App
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