[英]Checkbox fires only at multiple clicks
更新:我已經改進了一些東西並進行了更改。 現在,我必須第二次單擊,這是控制台第一次寫入:
Der Thread 0x180c hat mit Code 0 (0x0) geendet.(Thread stopped)
然后在第二個復選框中起作用。
OLD當我單擊復選框時,我的應用程序應訪問URL。 它是有效的,但前提是我在復選框上單擊了多次。
因此,當我想要停止它時,它將無法工作。 我不知道為什么。 與按鈕相同,我必須多次單擊它才能起作用。
private void chVisitProfile_CheckedChanged(object sender, EventArgs e)
{
if (chVisitProfile.Checked)
{
var threadLoading = new ThreadStart(StartVisiting);
var thread = new Thread(threadLoading);
thread.Start();
}
}
private void StartVisiting()
{
var jsDo = "var urls = '';" +
"$.each($('.tile__link').find('.info__username'), function(i, b){var profilname = '" + "https://www.website.com/#/profile/" + "' +$(this).text().trim() + '" + "@" + "';urls+=profilname;});" +
"function returnURL(){thURL = urls;return thURL;} returnURL();";
var task = chromeControll.EvaluateScriptAsync(jsDo);
task.ContinueWith(t =>
{
if (!t.IsFaulted)
{
var response = t.Result;
var EvaluateJavaScriptResult = response.Success ? (response.Result ?? "null") : response.Message;
richTextBox1.BeginInvoke((Action)(() => richTextBox1.Text = response.Result.ToString()));
}
});
var links = richTextBox1.Text;
string[] exploded = links.Split('@');
for (int i = 1; i < exploded.Length; i++)
{
if(chVisitProfile.Checked == false)
{
break;
}
Thread.Sleep(500);
chromeVisit.Load(exploded[i]);
//lblSeconds.Text = i.ToString();
}
}
為什么甚至不需要啟動線程呢? 我建議這樣的事情:
private void chVisitProfile_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
var threadLoading = new ThreadStart(StartVisiting);
var thread = new Thread(threadLoading);
thread.Start();
}
}
這樣,線程僅在需要時觸發。 為了進一步改進它,它可以驗證進程是否已經進行(因此無需啟動新線程)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.