newbie here, my form is monitoring Caps Lock status but is using around 50% of CPU, I think this is related to Application.Idle += Application_Idle and Application.Idle -= Application_Idle. Once I've removed those my form is not monitoring Caps Lock state, any suggestions?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CapsLockChecker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Application.Idle += Application_Idle;
}
private void Form1_Load(object sender, EventArgs e)
{
}
void Application_Idle(object sender, EventArgs e)
{
if (Control.IsKeyLocked(Keys.CapsLock))
{
label1.Text = "CapsLock is On";
pictureBox1.ImageLocation = "C:\\Users\\user\\source\\repos\\CapsLockChecker\\CapsLockChecker\\if_Circle_Green_34211.png";
}
else
{
label1.Text = "CapsLock if Off";
pictureBox1.ImageLocation = "C:\\Users\\user\\source\\repos\\CapsLockChecker\\CapsLockChecker\\if_Circle_Red_34214.png";
}
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
Application.Idle -= Application_Idle;
base.OnFormClosed(e);
}
}
}