First of all, I am creating new thread because I want to get the cursor location to be displayed on the form. So, here's what I did, inside the class, I created a thread and using that thread I am running that method which will assign cursor location to labels on my form.
public partial class Main : Form
{
public Main()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
private void GetCurLoc()
{
while (true)
{
PosX.Text = MousePosition.X.ToString();
PosY.Text = (Int32.Parse(PosYMax.Text) - MousePosition.Y).ToString();
}
}
private void Main_Load(object sender, EventArgs e)
{
Thread curLoc = new Thread(new ThreadStart(GetCurLoc));
curLoc.Start();
}
}
But, the application consumes so much CPU and power. Why one thread will consume such CPU? To me, it seems my thread creation is doing a resource leak.
Please help.