Noob_The_ Jacky
Member
- Joined
- Dec 21, 2020
- Messages
- 14
- Programming Experience
- Beginner
I am working on a window form program which is going to grab info from the web repeatedly. The program is basically copy from a console program which I use
.
However, when it come to window form program, it make the program super slow. What I want is the data going to come out one by one, but now is the program seem to be suspended and then lot of line come out suddenly .Below is the script:
But once the loop and the
are removed it work so smooth.
What is wrong with that ?
Thank you for your attention.
C#:
system.threading.thread.sleep(30*1000)
However, when it come to window form program, it make the program super slow. What I want is the data going to come out one by one, but now is the program seem to be suspended and then lot of line come out suddenly .Below is the script:
C#:
using System;
using System.Windows.Forms;
using HtmlAgilityPack;
using System.Net;
using System.IO;
namespace AAstockpriceWin
{
public partial class Form1 : Form
{
private static string Currenthtml = @"http://www.aastocks.com/tc/stocks/market/bmpfutures.aspx?future=200300";
private static string Nexthtml = @"http://www.aastocks.com/tc/stocks/market/bmpfutures.aspx?future=200301";
public static string Html;
public static int A=0;
public Form1()
{
InitializeComponent();
}
private void txtFilename_TextChanged(object sender, EventArgs e)
{
}
private void rd2_CheckedChanged(object sender, EventArgs e)
{
}
private void rd1_CheckedChanged(object sender, EventArgs e)
{
}
private void btnStartStop_Click(object sender, EventArgs e)
{
A++;
if (rd2.Checked) { Html = Nexthtml; } else { Html = Currenthtml; }
if (A % 2 == 0) { lbWorkornot.Text = "Stoped"; } else { lbWorkornot.Text = "Working"; }
while (A % 2 == 1) <<<<<<<<<<<<<<
{
Info();
}
}
private void txtResult_TextChanged(object sender, EventArgs e)
{
}
private void txtTimeinterval_TextChanged(object sender, EventArgs e)
{
}
public void Info()
{
WebClient httpins = new WebClient();
httpins.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0");
httpins.Headers.Add("Method", "GET");
DateTime now = DateTime.Now;
Stream resp = httpins.OpenRead(Form1.Html);
StreamReader resstring = new StreamReader(resp);
string s = resstring.ReadToEnd();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(s);
resstring.Close();
HtmlNode pricenode = doc.DocumentNode.SelectSingleNode("html/body/form/div[4]/div[1]/div[4]/div[5]/table/tr[1]/td[1]/div[4]");
HtmlNode pricenow = doc.DocumentNode.SelectSingleNode("html/body/form/div[4]/div/div[4]/div[5]/table/tr[7]/td/div[5]");
HtmlNode change = doc.DocumentNode.SelectSingleNode("/html/body/form/div[4]/div[1]/div[4]/div[5]/table/tr[1]/td[2]/div[4]/span");// html / body / form / div[4] / div[1] / div[4] / div[5] / table / tbody / tr[1] / td[2] / div[4] / span
HtmlNode premium = doc.DocumentNode.SelectSingleNode("/html/body/form/div[4]/div[1]/div[4]/div[5]/table/tr[1]/td[3]/div[4]"); //html/body/form/div[4]/div[1]/div[4]/div[5]/table/tbody/tr[1]/td[3]/div[4]
txtResult.Text += $"{now.ToString("HH:mm:ss")}\tPrice: {pricenode.InnerText.Trim()}\tPremiun: {premium.InnerText.Trim().Replace(" 23","")}\tChange: {change.InnerText.Trim()}\tPriceN: {pricenow.InnerText.Trim()}\r\n";
System.Threading.Thread.Sleep(Convert.ToInt32(txtTimeinterval.Text) * 1000); <<<<<<<<<<<<<<<<<<<<
}
}
}
C#:
System.Threading.Thread.Sleep(Convert.ToInt32(txtTimeinterval.Text) * 1000)
What is wrong with that ?
Thank you for your attention.