只需一步,快速开始
分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程
HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成
HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子
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; using System.Threading; using CsharpHttpHelper; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //创建一个委托,是为访问TextBox控件服务的。 public delegate void UpdateTxt(string msg); //定义一个委托变量 public UpdateTxt updateTxt; int jiangetime = 1; bool isstart = true; //修改TextBox值的方法。 public void UpdateTxtMethod(string msg) { richTextBox1.AppendText(msg + "\r\n"); richTextBox1.ScrollToCaret(); } //此为在非创建线程中的调用方法,其实是使用TextBox的Invoke方法。 public void ThreadMethodTxt(int n) { this.BeginInvoke(updateTxt, "线程开始执行,每" + n + "秒执行一次"); int c = 0; do { //---------------此处为你的刷票代码-------------// HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = "http://www.baidu.com",//URL 必需项 }; HttpResult result = http.GetHtml(item); string html = result.Html; //---------------此处为你的刷票代码-------------// c++; this.BeginInvoke(updateTxt, string.Format("第{0}次执行'{1}'", c.ToString(), html)); Thread.Sleep(n); if (isstart) { break; } } while (true); this.BeginInvoke(updateTxt, "线程结束" + c.ToString()); } private void btnEnter_Click(object sender, EventArgs e) { if (isstart) { isstart = false; btnEnter.Text = "暂停"; jiangetime = Convert.ToInt32(txttime.Text.Trim()) * 1000; Thread objThread = new Thread(new ThreadStart(delegate { ThreadMethodTxt(jiangetime); })); objThread.Start(); } else { isstart = true; btnEnter.Text = "开始"; } } private void Form1_Load(object sender, EventArgs e) { //实例化委托 updateTxt = new UpdateTxt(UpdateTxtMethod); } } }
使用道具 举报
zhengknight 发表于 2018-1-26 13:30 微信投票的能刷嘛?
本版积分规则 发表回复 回帖后跳转到最后一页
|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)
GMT+8, 2025-2-23 07:31
© 2014-2021