备忘

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Fizzler;
using Fizzler.Systems;
using Fizzler.Systems.HtmlAgilityPack;
using Fizzler.Systems.XmlNodeQuery; namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Uri url = new Uri("http://www.c-sharpcorner.com/forums/Search/?forum=0&searchtype=0&searchtext=");
runBrowserThread(url);
} static private void runBrowserThread(Uri url)
{
var th = new Thread(() =>
{
var br = new WebBrowser();
br.DocumentCompleted += browser_DocumentCompleted;
br.Navigate(url); TimerCallback timerDelegate = new TimerCallback(CheckStatus);
//System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(timerDelegate, br.DocumentText, 1000, 1000);
System.Windows.Forms.Timer timers = new System.Windows.Forms.Timer();
timers.Enabled = true;
timers.Interval = 1000;
timers.Tick += delegate(object o, EventArgs args)
{
CheckStatus(br.DocumentText);
};
timers.Start();
Application.Run();
//Application.DoEvents(); });
th.SetApartmentState(ApartmentState.STA);
th.Start();
} static void CheckStatus(Object state)
{ try
{ string html = state.ToString(); // Console.WriteLine(html);
if (checklistbape(html))
{
//这里主要用来进行ajax检测
//检测成功后,对内容进行处理
//定时器对页面状态进行轮训和判断进行那个操作
Console.WriteLine("OK"); // Application.ExitThread(); // Stops the thread
}
else
{
Console.WriteLine("= =");
}
}
catch (Exception ex)
{
string ss = "";
}
}
private static bool checklistbape(string htmltext)
{
var html = new HtmlAgilityPack.HtmlDocument();
html.LoadHtml(htmltext);
var document = html.DocumentNode;
var urlnode = document.QuerySelectorAll(".latestArticle>li").ToList();
var next = document.QuerySelectorAll(".pagingSpritIcons").ToList();
if (urlnode.Count == 0 || next.Count == 0)
{
return false;
}
else
{
return true;
}
}
static void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var br = sender as WebBrowser;
if (br.Url == e.Url)
{
Console.WriteLine("Natigated to {0}", e.Url);
// Application.ExitThread(); // Stops the thread
}
} }
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

WebBrowser 多线程 DocumentCompleted 和定时器的更多相关文章

  1. WebBrowser 的 DocumentCompleted事件不执行的解决方法

    原文:WebBrowser 的 DocumentCompleted事件不执行的解决方法 WebBrowser 的 DocumentCompleted事件不执行的解决方法: 使用WebBrowser的P ...

  2. Java多线程19:定时器Timer

    前言 定时/计划功能在Java应用的各个领域都使用得非常多,比方说Web层面,可能一个项目要定时采集话单.定时更新某些缓存.定时清理一批不活跃用户等等.定时计划任务功能在Java中主要使用的就是Tim ...

  3. java 多线程Thread 子类 定时器Timer

    定时器Timer, 定时器分类: 1,指定时间指定任务(明天早上8点准时提醒我起床),相当于linux里面的at命令 2,周期性的执行任务(每隔三分钟闹钟响一次),相当于Linux里面的cron命令 ...

  4. Java多线程编程核心技术--定时器

    Timer类主要负责计划任务,也就是在指定的时间开始执行某一个任务. 方法schedule(TimerTask task, Date time) public class Task { private ...

  5. C#:WebBrowser控件的使用教程及相关问题整理

    推荐阅读: C#WebBrowser控件使用教程与技巧收集--苏飞收集 C# WebBrowser强制在本窗口打开,禁止在新窗口打开 C# WebBrowser禁止在新窗口打开,强制在本窗口打开(多种 ...

  6. C 实现一个跨平台的定时器 论述

    引言 今天我们要讲述和构建的是一个跨平台多线程C的定时器对象,粒度是毫秒级别.可以称之为简易的timer, sctimer.h 库. 首先看总的接口,看门见客. sctimer.h #ifndef _ ...

  7. c#winform使用WebBrowser 大全[超长文转载]

    1.主要用途:使用户可以在窗体中导航网页. 2.注意:WebBrowser 控件会占用大量资源.使用完该控件后一定要调用 Dispose 方法,以便确保及时释放所有资源.必须在附加事件的同一线程上调用 ...

  8. [转载]WebBrowser控件表单(form)的自动填写和提交

    话说有了WebBrowser类,终于不用自己手动封装SHDocVw的AxWebBrowser这个ActiveX控件了.这个类如果仅仅作为一个和IE一模一样浏览器,那就太没意思了(还不如直接用IE呢). ...

  9. .Net 2.0实例学习:WebBrowser页面与WinForm交互技巧

    原文:.Net 2.0实例学习:WebBrowser页面与WinForm交互技巧 最近看到博客园入门教学文章比较流行,自己最近又偷懒比较多,没啥心得,不妨写一篇没啥深度的入门文章吧. 话说有了WebB ...

随机推荐

  1. HTML学习之Web存储(五)

    本地数据库功能大大增强了Web应用对于本地存储数据的方式和功能.Web时代真正进入了:“客户端为重,服务端为轻的时代”. <!DOCTYPE html> <html xmlns=&q ...

  2. ASP.NET Web API 中的异常处理(转载)

    转载地址:ASP.NET Web API 中的异常处理

  3. 缓慢变化维 (Slowly changing dimension)

          维度建模的数据仓库中,有一个概念叫Slowly Changing Dimensions,中文一般翻译成"缓慢变化维",经常被简写为SCD.缓慢变化维的提出是因为在现实世 ...

  4. Codeforces Round #363 Fix a Tree(树 拓扑排序)

    先做拓扑排序,再bfs处理 #include<cstdio> #include<iostream> #include<cstdlib> #include<cs ...

  5. wp8 入门到精通 仿QQPivot 提示数量

    <Grid x:Name="LayoutRoot" Background="White"> <Grid Width="480&quo ...

  6. php判断当前的访问是手机还是电脑

    <?php function check_wap() { if (isset($_SERVER['HTTP_VIA'])) return true; if (isset($_SERVER['HT ...

  7. C#从Image上读取文本

    今天通过C#来实现一个读取Image上文本的功能. 1. 环境准备: 1). 下载 Microsoft Office SharePoint Designer 2007. 2). 安装请参考KB:htt ...

  8. 重新开始刷dp,哈哈哈

    转载于: http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2015年1月29日 从头开始

  9. 装饰模式/decorator模式/结构型模式

    装饰模式Decorator 定义 为对象动态的增加新的功能,实现要求装饰对象和被装饰对象实现同一接口或抽象类,装饰对象持有被装饰对象的实例. java实现要点 定义一个接口或抽象类,作为被装饰者的抽象 ...

  10. UI中 frame 与 transform的用法与总结

    在iOS中,我们是不可以直接访问控件中frame的结构体的成员的,因此我们需要分三步来改变一个UI控件的位置,大小 一.frame用法 frame的结构体类型为: struct CGRect { CG ...