码迷,mamicode.com
首页 > 其他好文 > 详细

数据采集(天天,百度百家)

时间:2017-09-06 18:24:48      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:interval   ret   cond   datetime   scrollto   form   ++   date   bre   

爆文采集系统后台数据支撑:百度百家以及天天快报等等。。

 

简单采集过程,不再复述。

重点放在新学的线程以及桌面应用程序:

1、线程部分,   开始、暂停、继续、结束

 1      public enum opState
 2         {
 3             none,   //无操作
 4             pause,  //暂停
 5             go_on,  //继续
 6             stop    //停止
 7         }
 8         private Thread myThread = null;
 9         private bool myThreadRun = false;
10         private opState state = opState.none;
11         private delegate void ShowMsgHandler(string msg);
12         public Form1()
13         {
14             InitializeComponent();
15         }
16 
17         /// <summary>
18         /// 开始
19         /// </summary>
20         private void button1_Click(object sender, EventArgs e)
21         {
22             if (myThread == null || myThread.ThreadState == ThreadState.Stopped)
23             {
24                 myThreadRun = true;
25                 myThread = new Thread(new ThreadStart(runPro));
26                 myThread.IsBackground = true;
27                 myThread.Start();
28             }
29             else
30             {
31                 myThreadRun = false;
32             }
33         }
34 
35         public void runPro()
36         {
37             for (int i = 0; i < 10000; i++)
38             {
39                 //状态开关控制
40                 switch (state)
41                 {
42                     case opState.pause:
43                         i--;
44                         continue;
45                     case opState.go_on:
46                         break;
47                     case opState.none:
48                         break;
49                     case opState.stop:
50                         return;
51                 }
52                 if (this.InvokeRequired)
53                 {
54                     this.Invoke(new ShowMsgHandler(ShowMsg), i.ToString());
55                 }
56                 else
57                 {
58                     ShowMsg(i.ToString());
59                 }
60                 //Thread.Sleep(100);
61             }
62         }
63         private void ShowMsg(string msg)
64         {
65             this.textBox1.AppendText(msg + "\r\n");
66         }
67 
68         /// <summary>
69         /// 暂停
70         /// </summary>
71         private void button2_Click(object sender, EventArgs e)
72         {
73             state = opState.pause;
74         }
75 
76         /// <summary>
77         /// 继续
78         /// </summary>
79         private void button3_Click(object sender, EventArgs e)
80         {
81             state = opState.go_on;
82         }
83 
84         /// <summary>
85         /// 停止
86         /// </summary>
87         private void button4_Click(object sender, EventArgs e)
88         {
89             state = opState.stop;
90             myThreadRun = false;
91         }

2、窗体应用程序

2.1、异步加载输出

1 this.Invoke(new Action(() =>
2 {
3   label2.Text = subject_name;
   textBox.AppendText("" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】 ----添加新作者:" + writer_name + "\r\n" + "\r\n"); 5 textBox.ScrollToCaret();//下拉框 6 }));

2.2、时间插件

ps:记得修改插件属性Interval的值为1000

 1 private void timer1_Tick(object sender, EventArgs e)
 2         {
 3             Second_++;
 4             if (Second_ == 60)
 5             {
 6                 Second_ = 0;
 7                 Minute_++;
 8             }
 9             if (Minute_ == 60)
10             {
11                 Minute_ = 0;
12                 Hour_++;
13             }
14             label7.Text = Hour_ + "" + Minute_ + "" + Second_;
15         }

-----------kylin

数据采集(天天,百度百家)

标签:interval   ret   cond   datetime   scrollto   form   ++   date   bre   

原文地址:http://www.cnblogs.com/yishilin/p/7486054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!