using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Net; namespace pesse { public partial class Form1 : Form { private List<System.Threading.Thread> Th_List=new List<System.Threading.Thread>(); private int count ; delegate void SetTextCallback(string text); public Form1() { InitializeComponent(); } public void WT(string ss) { if (TList.InvokeRequired) { SetTextCallback d = new SetTextCallback(WT); this.Invoke(d, new object[] { ss }); } else { TList.Items.Add(ss); } } private void btn_Start_Click(object sender, EventArgs e) { Temp T; count =Convert.ToInt16(txt_Count.Text); System.Threading.Thread th; for (int i = 0;i < count;i++) { T = new Temp(this); T.time = Convert.ToDouble(txt_Time.Text)*1000; T.name = i; th = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Start)); th.Start(T); Th_List.Add(th); } btn_Start.Enabled = false; } public static void Start(object t) { Temp f = (Temp)t; f.Write(f.name + " 开始了"); while (true) { System.Threading.Thread.Sleep(Convert.ToInt32(f.time)); XF.CXFDService XFS = new pesse.XF.CXFDService(); string theURL; int change=0; Random randObj = new Random(); int start = 1;//随机数可取该下界值 int end = 10;//随机数不能取该上界值 change= randObj.Next(start, end); try { switch (change) { case 0: case 1: case 2: { } } catch (Exception ee) { f.Write(ee.Message); } } } private void btn_Stop_Click(object sender, EventArgs e) { for (int i = 0; i < Th_List.Count; i++) { Th_List[i].Abort(); } Application.Exit(); } private void TList_SelectedIndexChanged(object sender, EventArgs e) { } } public class Temp { public int name; public double time; private Form1 ff; public Temp(Form1 f) { ff = f; } public void Write(string str) { ff.WT(str); } } }