改了一下代码,过二秒后只有一个线程的问题解决了,是实例化错了的事.现在还是执行长时间的会卡死..
[C#] 纯文本查看 复制代码 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.Runtime.InteropServices;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
delegate void qianggou(int id);
System.Threading.Timer[] threadTimer=new System.Threading.Timer[10];
bool[] temp = new bool[] { false, false, false, false, false, false, false, false, false, false};
public void ThreadMethod(Object state)
{
this.Invoke(new qianggou(jdordertotal), state);
}
private void qiang_Click(object sender, EventArgs e)
{
for(int i=0;i<10;i++)
{
threadTimer[i] = new System.Threading.Timer(new System.Threading.TimerCallback(ThreadMethod), i, 0, 1000);
Thread.Sleep(100);
}
}
public void jdordertotal(int id)
{
TimeSpan ts = Convert.ToDateTime("2014-3-9 13:35:00") - DateTime.Now;
double zms = ts.TotalMilliseconds;
double zs = ts.TotalMilliseconds / 1000;
string tt = zs.ToString("0.0");
timestatus.Text = tt;
if (zs < 60)
{
testbig(id);
}
}
public void testbig(int id)
{
//threadTimer[id].Change(-1,-1);
test2.Text = id.ToString();
//Thread.Sleep(1000);
//threadTimer[id].Change(0, 5000);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
|