可以Application.DoEvents()在C#中使用吗?
这个函数是否能够让GUI跟上应用程序的其余部分,就像VB6 DoEvents一样?
我有一个列表Uri,我想要"点击"为了达到这个目的,我试图为每个Uri创建一个新的Web浏览器控件.我为每个Uri创建一个新线程.我遇到的问题是文档在文档之前结束是完全加载的,所以我永远不会使用DocumentComplete事件.我怎么能克服这个?
var item = new ParameterizedThreadStart(ClicIt.Click);
var thread = new Thread(item) {Name = "ClickThread"};
thread.Start(uriItem);
public static void Click(object o)
{
var url = ((UriItem)o);
Console.WriteLine(@"Clicking: " + url.Link);
var clicker = new WebBrowser { ScriptErrorsSuppressed = true };
clicker.DocumentCompleted += BrowseComplete;
if (String.IsNullOrEmpty(url.Link)) return;
if (url.Link.Equals("about:blank")) return;
if (!url.Link.StartsWith("http://") && !url.Link.StartsWith("https://"))
url.Link = "http://" + url.Link;
clicker.Navigate(url.Link);
}
Run Code Online (Sandbox Code Playgroud) Sometimes, once I have requested the cancellation of a pending task with CancellationTokenSource.Cancel, I need to make sure the task has properly reached the cancelled state, before I can continue. Most often I face this situation when the app is terminating and I want to cancel all pending task gracefully. However, it can also be a requirement of the UI workflow specification, when the new background process can only start if the current pending one has been fully …
我正在使用自动测试脚本,并使用WebBrowser控件.我试图在用户接受服务条款时提交以下HTML并进行测试:
<form action="http://post.dev.dealerconnextion/k/6hRbDTwn4xGVl2MHITQsBw/hrshq" method="post">
<input name="StepCheck" value="U2FsdGVkX18zMTk5MzE5OUgFyFgD3V5yf5Rwbtfhf3gjdH4KSx4hqj4vkrw7K6e-" type="hidden">
<button type="submit" name="continue" value="y">ACCEPT the terms of use</button>
<button type="submit" name="continue" value="n">DECLINE the terms of use</button>
</form>
// Terms of Use Information
<form action="http://post.dev.dealerconnextion/k/6hRbDTwn4xGVl2MHITQsBw/hrshq" method="post">
<input name="StepCheck" value="U2FsdGVkX18zMTk5MzE5OUgFyFgD3V5yf5Rwbtfhf3gjdH4KSx4hqj4vkrw7K6e-" type="hidden">
<button type="submit" name="continue" value="y">ACCEPT the terms of use</button>
<button type="submit" name="continue" value="n">DECLINE the terms of use</button>
</form>
Run Code Online (Sandbox Code Playgroud)
这是C#中的代码,但不提交表单.
HtmlElementCollection el = webBrowser.Document.GetElementsByTagName("button");
foreach (HtmlElement btn in el)
{
if (btn.InnerText == "ACCEPT the terms of use")
{
btn.InvokeMember("Click");
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激.谢谢.
c# ×4
.net ×1
async-await ×1
automation ×1
browser ×1
doevents ×1
forms ×1
submit ×1
winforms ×1