如何根据当前日期时间延迟计时器的运行或启动计时器

时间:2017-02-23 15:44:48

标签: c# multithreading

我有一个控制台应用程序使用作为App的演示,它打印" hello",基于预期提醒用户的时间跨度。当它还没有时间跨度时,我想延迟应用程序打印你好,并在时间恢复。

  public static async void timeCounter(int delae)
    {
        //This is suppose to cause a delay but it instead initiate the
        //TimerOperation_Tick method.
        await Task.Delay(delae);


        //  timer countdown




        System.Timers.Timer timer = new System.Timers.Timer();
        timer.Interval = 1000; // 1 second 
        timer.Elapsed += new ElapsedEventHandler(TimerOperation_Tick);
        timer.Start();
        if (obj.SubmissionCheck == true)
        {
            timer.Stop();

        }


    }

/// the event subscriber
 private static void TimerOperation_Tick(object e, ElapsedEventArgs args)
    {
        if (timeFrame != 0)
        {
            Console.WriteLine("hi" + timeFrame);
            timeFrame --;

          if (timeFrame < 1)
          {
            obj.SubmissionCheck = true;
            nt.Remove(obj);
              startNotification();

          }
        }

    }

0 个答案:

没有答案