一个可以刷PV的工具

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
namespace IE
{
 /// <summary>
 /// Main 的摘要说明。
 /// </summary>
 public class DlgMain : System.Windows.Forms.Form
 {
  
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Button bt_Start;
  private System.Windows.Forms.Button bt_Back;
  private System.Windows.Forms.Button bt_Stop;
  private System.Windows.Forms.TextBox tx_url;

  //数组保存当前线程
  internal static Hashtable threads = new Hashtable();
  static int MAX_THREAD= 10;  //同时打开的进程数
  static bool IsBack = false;  //是否工作在后台
  Thread Mythread;

  private bool ConnFlags=false;
  private System.Windows.Forms.Label lb_ThreadMun;
  private System.Windows.Forms.TextBox txUrl;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

  public DlgMain()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if(components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.tx_url = new System.Windows.Forms.TextBox();
   this.label1 = new System.Windows.Forms.Label();
   this.bt_Start = new System.Windows.Forms.Button();
   this.bt_Back = new System.Windows.Forms.Button();
   this.bt_Stop = new System.Windows.Forms.Button();
   this.lb_ThreadMun = new System.Windows.Forms.Label();
   this.txUrl = new System.Windows.Forms.TextBox();
   this.SuspendLayout();
   //
   // tx_url
   //
   this.tx_url.Location = new System.Drawing.Point(72, 18);
   this.tx_url.Name = "tx_url";
   this.tx_url.Size = new System.Drawing.Size(216, 21);
   this.tx_url.TabIndex = 0;
   this.tx_url.Text = "http://www.xiangruiniandai.com";
   //
   // label1
   //
   this.label1.Location = new System.Drawing.Point(32, 24);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(48, 16);
   this.label1.TabIndex = 1;
   this.label1.Text = "网址:";
   //
   // bt_Start
   //
   this.bt_Start.Location = new System.Drawing.Point(136, 96);
   this.bt_Start.Name = "bt_Start";
   this.bt_Start.Size = new System.Drawing.Size(48, 24);
   this.bt_Start.TabIndex = 2;
   this.bt_Start.Text = "开 始";
   this.bt_Start.Click += new System.EventHandler(this.bt_Start_Click);
   //
   // bt_Back
   //
   this.bt_Back.Location = new System.Drawing.Point(248, 96);
   this.bt_Back.Name = "bt_Back";
   this.bt_Back.Size = new System.Drawing.Size(48, 24);
   this.bt_Back.TabIndex = 3;
   this.bt_Back.Text = "后 台";
   this.bt_Back.Click += new System.EventHandler(this.bt_Back_Click);
   //
   // bt_Stop
   //
   this.bt_Stop.Location = new System.Drawing.Point(192, 96);
   this.bt_Stop.Name = "bt_Stop";
   this.bt_Stop.Size = new System.Drawing.Size(48, 24);
   this.bt_Stop.TabIndex = 4;
   this.bt_Stop.Text = "停 止";
   this.bt_Stop.Click += new System.EventHandler(this.bt_Stop_Click);
   //
   // lb_ThreadMun
   //
   this.lb_ThreadMun.Location = new System.Drawing.Point(24, 96);
   this.lb_ThreadMun.Name = "lb_ThreadMun";
   this.lb_ThreadMun.TabIndex = 5;
   this.lb_ThreadMun.Text = "label2";
   //
   // txUrl
   //
   this.txUrl.Location = new System.Drawing.Point(72, 48);
   this.txUrl.Name = "txUrl";
   this.txUrl.Size = new System.Drawing.Size(216, 21);
   this.txUrl.TabIndex = 6;
   this.txUrl.Text = "http://www8.itsun.com/count.php?uuid=1720409&style=icon";
   //
   // DlgMain
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(344, 141);
   this.Controls.Add(this.txUrl);
   this.Controls.Add(this.lb_ThreadMun);
   this.Controls.Add(this.bt_Stop);
   this.Controls.Add(this.bt_Back);
   this.Controls.Add(this.bt_Start);
   this.Controls.Add(this.tx_url);
   this.Controls.Add(this.label1);
   this.Name = "DlgMain";
   this.Text = "刷网站PV";
   this.Load += new System.EventHandler(this.Main_Load);
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new DlgMain());
   
  }

  private void Main_Load(object sender, System.EventArgs e)
  {
  
  }

  private void bt_Start_Click(object sender, System.EventArgs e)
  {
   
   this.bt_Stop.Enabled = true;
   this.bt_Start.Enabled = false;

   Mythread = new Thread(new ThreadStart(this.MyThread_Strat));
   //Mythread.IsBackground = true;
   //Mythread.Priority = ThreadPriority.Lowest;
   Mythread.Start();
   
   //MyThread_Strat();
   
  }

  //退出所有线程
  private void  MyStopThread()
  {
   int i=0;

    for(i=0; i< MAX_THREAD;i++)
    {
     Hashtable syncThreads = Hashtable.Synchronized(threads);
     if(threads.Contains(i))
     {
      if(((Thread)syncThreads[i]).IsAlive != false)
      {
       ((Thread)syncThreads[i]).Abort();
       
      }
     }
     
    }
   
  }
  //返回线程池中终止的进程
  private int MyGetThread()
  {
   int i=0;
   for(;;)
   {
    for(i=0; i< MAX_THREAD;i++)
    {
     Hashtable syncThreads = Hashtable.Synchronized(threads);
     if(threads.Contains(i))
     {
      if(((Thread)syncThreads[i]).IsAlive == false)
      {
       ((Thread)syncThreads[i]).Abort();
       syncThreads.Remove(i);
       return i;
      }
     }
     else
     {
      syncThreads.Remove(i);
      return i;
     }
    }
    Thread.Sleep(500);
    
   }
   return i;
  }
  private void MyThread_Strat()
  {
   
   ConnFlags=true;
   int i=0,c=1;
   string s="*",ss="*";
   while(ConnFlags)
   {
    if (c > 10) c=1;
    i=this.MyGetThread();
    Thread thread = new Thread(new ThreadStart(this.MyThread));
    thread.IsBackground = true;
    thread.Priority = ThreadPriority.Lowest;
    thread.Start();
    Hashtable syncThreads = Hashtable.Synchronized(threads);
    syncThreads.Add(i,thread);
    
    s="";
    for(int j=0;j< c;j++)
    {
     s=s+ss;
    }
    this.lb_ThreadMun.Text = s; 
    c++;
    //Thread.Sleep(100);
   }
   this.lb_ThreadMun.Text = "正在退出所有进程,请等待...";
   //退出所有线程
   MyStopThread();
   this.lb_ThreadMun.Text = "所有进程退出完毕";
  }
 
  private void MyThread()
  {
   WebClient wbc = new WebClient();
   try
   {
    Stream myStream = wbc.OpenRead(this.tx_url.Text);
    //StreamReader rmy = new StreamReader(myStream);
    //StreamWriter wmy = new StreamWriter("d://dddd.txt");
    //wmy.Write(rmy.ReadToEnd());
    //wmy.Close();
    //wbc =new WebClient();
    Stream my =wbc.OpenRead(this.txUrl.Text);

    //Thread.Sleep(10000);
    myStream.Close();
    my.Close();
   }
   catch
   {

   }
   //MessageBox.Show("退出");
  }
  
  private void bt_Stop_Click(object sender, System.EventArgs e)
  {
   this.bt_Start.Enabled = true;
   this.bt_Stop.Enabled = false;
   ConnFlags = false;
  }

  

  private void bt_Back_Click(object sender, System.EventArgs e)
  {
   
  }
  
 }

}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值