Is there a way to implement an active window dectector to a toggle?
So I want a program to do a function when the toggle is toggled and the program is not in focus. This is the current code.
private void Toggle_CheckedChanged(object sender, EventArgs e) { while (Toggle.Checked = true) { FUNCTION } }
I would like it to be like this
private void Toggle_CheckedChanged(object sender, EventArgs e) { while (Toggle.Checked = true) & activewindow = false { FUNCTION } }
I have already tried implementing different functions, but it was flagged as ‘method group’.
Does anyone know how to do this?
You can use async/await
to accomplish this:
private async void Toggle_CheckedChanged(object sender, EventArgs e) { while(Toggle.Checked) { await Task.Delay(250); // you need some kind of delay in the loop...maybe? if (!ApplicationIsActivated()) { await Task.Run(() => { FUNCTION(); }); } } }