gpt4 book ai didi

javascript - 应用程序运行时崩溃

转载 作者:行者123 更新时间:2023-12-03 06:51:11 24 4
gpt4 key购买 nike

这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MafiaspilletBot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.Navigate("http://mafiaspillet.no/");
webBrowser1.ScriptErrorsSuppressed = true;
}

private void button1_Click(object sender, EventArgs e)
{
SendData();
}
private void SendData()
{
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("brukernavn")[0].SetAttribute("value", textBox2.Text);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("passord")[0].SetAttribute("value", textBox1.Text);
System.Threading.Thread.Sleep(5000);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("login_buton")[0].InvokeMember("click");
System.Threading.Thread.Sleep(10000);
DoKrims();
}
private void DoKrims()
{
webBrowser1.Navigate("http://mafiaspillet.no/kriminalitet3.php");
System.Threading.Thread.Sleep(10000);
webBrowser1.Document.GetElementById("submit").InvokeMember("click");
}
}
}

但是每次我运行它并填写 textBox1textBox2 并通过应用程序提交它们时,整个窗口就会停止工作。我的代码中是否有任何内容可能会导致此问题,或者我可以做些什么来摆脱此问题?另外,我从未使用过 C#,这是我第一次用 C# 制作和完成,因为我认为学习 C# 会很有趣。无论如何,要加载的网站使用了大量的 JavaScript,我找不到让 webBrowser1 使用它们的方法,所以我使用了 webBrowser1.ScriptErrorsSuppressed = true; 忽略错误消息。

最佳答案

据我所知,您正在使用:

System.Threading.Thread.Sleep(5000);
System.Threading.Thread.Sleep(10000);
System.Threading.Thread.Sleep(10000);

这将使您的应用程序在每次执行 button1_Click 时有 25 秒无响应。它会发生,因为它全部由一个线程处理。为了避免它尝试在单独的线程中执行SendData()

简单的例子是:

Thread SendThread = new Thread(SendData);
SendThread.Start();

您可以尝试在此处阅读线程 Run simple thread

关于javascript - 应用程序运行时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com