static void Main(string[] args)
{
//多个线程修改同一个值,使用lock锁解决并发
for (int i = 0; i < 4; 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 <= 10; i++)
{
Number = i;
Console.WriteLine("当前线程:{0},Number={1}", Thread.CurrentThread.ManagedThreadId, Number);
Thread.Sleep(200);
}
}
}
}
/// <summary>
/// 定时执行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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 <= 100
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();
}