• winfrom 多线程 并发 和定时任务


    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();
    }

  • 相关阅读:
    Yii2中把路由地址中的%2F改为/
    深度解析常用的软件开发模型
    MYSQL索引的类型和索引的方式
    mysql errno 150
    士兵杀敌(五)
    stringstream字符串流
    士兵杀敌(二)(线段树+树状数组)
    士兵杀敌(一)(树状数组)
    C语言文件读写操作总结
    BC第二场
  • 原文地址:https://www.cnblogs.com/yangpeng-jingjing/p/9674642.html
Copyright © 2020-2023  润新知