I'm using CefSharp and wanted it when I clicked the button to run the javascript
every 1 second and in the background too, and only stop if I click the shutdown button. I tried the backgroundworker but I could not, I'm kind of lazy in that part:
When you click the button the background worker executes:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
bool rodando = true;
chromeBrowser.ExecuteScriptAsync("$(document).ready(function(){if($('#signup_button').is(':visible')){alert('Você precisa estar logado para utilizar o script')}})");
try
{
Thread t = new Thread(() =>
{
while (rodando)
{
Thread.Sleep(1000);
Script();
}
});
t.Start();
}
catch
{
}
}
Shutdown button:
private void btnscriptshutdown_Click(object sender, EventArgs e)
{
if (worker.WorkerSupportsCancellation)
worker.CancelAsync();
}
Just do not do the loop, just run once, how can I do to always execute?