winfrom 多线程 并发 和定时任务

2021-06-23 05:05

阅读:684

标签:sum   null   thread   new   string   static   star   main   nta   

static void Main(string[] args)
{


//多个线程修改同一个值,使用lock锁解决并发
for (int i = 0; i {
Task.Factory.StartNew(ThreadMethod2);
}
//Thread.Sleep(2000);
Console.ReadKey();
}

public static int Number = 1;
public static void ThreadMethod2()
{
while (true)
{
lock (typeof(Program))
{
//Number++;
//Console.WriteLine("当前线程:{0},Number={1}", Thread.CurrentThread.ManagedThreadId, Number);
//Thread.Sleep(500);
for (int i =1; i {
Number = i;
Console.WriteLine("当前线程:{0},Number={1}", Thread.CurrentThread.ManagedThreadId, Number);
Thread.Sleep(200);
}
}
}
}

 

 

///


/// 定时执行
///

///
///
private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Stop();
#region
string sql = @"SELECT
A.GUID,
A.BILL_CODE,
A.STATUS,
A.TYPE,
D.PATH,
CF.TAG_ALIAS,
A.REPORT_NAME,
D.LABLE_NAME
FROM TAB_REPORT_PRINT A
LEFT JOIN TAB_REPORT_LABEL D
ON A.REPORT_NAME = D.LABLE_NAME
LEFT JOIN TAB_TAG_CONF CF
ON D.LABLE_NAME = CF.TAG_ALIAS
LEFT JOIN TAB_TAG_TYPE TE
ON CF.GUID = TE.TAG_CODE
WHERE 1 = 1
AND STATUS = 0
AND ROWNUM ORDER BY A.INSERT_DATE ASC";
#endregion
dt_data = SelectData(sql).Tables[0];

if (dt_data != null && dt_data.Rows.Count > 0)
{
foreach (DataRow dr in dt_data.Rows)
{
if (!string.IsNullOrWhiteSpace(dr["PATH"].ToString()))
{
LoadTemplate(dr);
}
}
}
this.timer1.Start();
}

winfrom 多线程 并发 和定时任务

标签:sum   null   thread   new   string   static   star   main   nta   

原文地址:https://www.cnblogs.com/yangpeng-jingjing/p/9674642.html

上一篇:编程语言的介绍

下一篇:Python爬虫小记


评论


亲,登录后才可以留言!