111,129
社区成员
发帖
与我相关
我的任务
分享
private void time_send()
{
string sql="select * from TB where sendyorn=0"
SqlConnection con = conn();
try
{
SqlDataAdapter adap = new SqlDataAdapter(sql, con);
SqlCommandBuilder scb = new SqlCommandBuilder(adap);
DataTable dt = new DataTable();
adap.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
url += "Username=" + this.t_uid.Text.ToString();
string success = succ_flag.Text.ToString();
string DOresult = this.DoUrl(url); //提交URL的方法
dt.Rows[i]["sendyorn"] = 1; //置标识为1,为已检索
adap.Update(dt);
try
{
System.Threading.Thread.Sleep(300); //这样写对不?
}
catch
{
}
Application.DoEvents();
}
}
catch (Exception ep)
{
this.log(ep.Message);
}
finally
{
con.Close();
}
}
new Thread(new ThreadStart(delegate() {
time_send();
})).Start();
//定义控件委托
deletage void delevoid0(string s);
private void log(string msg)
{
Control ctl=(Control)tb_log;
if(ctl.InvokeRequired)
{
delevoid0 d=new delevoid0(log);
ctl.Invoke(d,new object[]{msg};
return;
}
string time = DateTime.Now.ToString("yyyyMMdd HH:mm:ss:ffff");
tb_log.Text = "【" + time + "】" + msg + "\r\n" + tb_log.Text;//你实际在多线程中只引用了这个tb_log控件。
}private void time_send()
{
string sql="select * from TB where sendyorn=0"
SqlConnection con = conn();
try
{
SqlDataAdapter adap = new SqlDataAdapter(sql, con);
SqlCommandBuilder scb = new SqlCommandBuilder(adap);
DataTable dt = new DataTable();
adap.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
url += "Username=" + this.t_uid.Text.ToString();
string success = succ_flag.Text.ToString();
string DOresult = this.DoUrl(url); //提交URL的方法,这个方法里面有没有涉及到其他控件?
dt.Rows[i]["sendyorn"] = 1; //置标识为1,为已检索
adap.Update(dt);
/*try
{
System.Threading.Thread.Sleep(300); //这样写对不?
}
catch
{
}
Application.DoEvents();*/不需要这一段
}
}
catch (Exception ep)
{
this.log(ep.Message);//这里使用了this代表啥,是这个窗体?
}
finally
{
con.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
new Thread(new ThreadStart(delegate() {
show("neirong", "biaoti");
})).Start();
}
public void show(string text, string title)
{
MessageBox.Show(text, title);
}