国产亚洲精品AA片在线观看,丰满熟妇HD,亚洲成色www成人网站妖精,丁香五月天婷婷五月天男人天堂

新聞中心

EEPW首頁(yè) > 消費(fèi)電子 > 設(shè)計(jì)應(yīng)用 > Timer定時(shí)器的設(shè)計(jì)方法

Timer定時(shí)器的設(shè)計(jì)方法

作者: 時(shí)間:2018-09-04 來源:網(wǎng)絡(luò) 收藏

本文引用地址:http://www.ljygm.com/article/201809/388353.htm

  /**////

  /// 委托

  ///

  private TimerCallback timerDelegate;

  /**////

  /// 靜態(tài)實(shí)例

  ///

  private static readonly PaperManager self = new PaperManager();

  /**////

  /// 構(gòu)造函數(shù)

  ///

  public PaperManager()

  {

  timerDelegate = new TimerCallback(CheckStatus);

  }

  /**////

  ///

  ///

  ///

  public static PaperManager getInstance()

  {

  return self;

  }

  /**////

  /// 設(shè)置啟動(dòng)時(shí)間間隔

  ///

  ///

  ///小時(shí)

  ///分鐘

  ///

  ///毫秒

  public void setDueTime(int days, int hours, int minutes, int seconds, int milisecond)

  {

  dueTime = new TimeSpan(days, hours, minutes, seconds, milisecond);

  }

  /**////

  /// 設(shè)置回調(diào)時(shí)間間隔

  ///

  ///

  ///小時(shí)

  ///分鐘

  ///

  ///毫秒

  public void setPeriod(int days, int hours, int minutes, int seconds, int milisecond)

  {

  period = new TimeSpan(days, hours, minutes, seconds, milisecond);

  }

  /**////

  /// 開始

  ///

  public void Start()

  {

  AutoResetEvent autoEvent = new AutoResetEvent(false);

  dueTime = TimeSpan.FromSeconds(0);

  period = TimeSpan.FromSeconds(10);

  iTimer = new Timer(timerDelegate, autoEvent, dueTime, period);

  autoEvent.WaitOne(5000, false);

  iTimer.Change(dueTime, period);

  }

  /**////

  /// 停止

  ///

  public void Stop()

  {

  iTimer.Dispose();

  }

  /**////

  /// 執(zhí)行一次

  ///

  public void ExcuteOneTime()

  {

  if (iTimer != null)

  {

  iTimer.Dispose();

  }

  //如果 period 為零 (0) 或 -1 毫秒,而且 dueTime 為正,則只會(huì)調(diào)用一次 callback;

  //計(jì)時(shí)器的定期行為將被禁用,但通過使用 Change 方法可以重新啟用該行為。

  setDueTime(0, 0, 0, 0, 1);

  setPeriod(0, 0, 0, 0, -1);

  AutoResetEvent autoEvent = new AutoResetEvent(false);

  iTimer = new Timer(timerDelegate, autoEvent, dueTime, period);

  autoEvent.WaitOne(5000, false);

  iTimer.Change(dueTime, period);

  }

  /**////

  /// 行為

  ///

  ///

  public void CheckStatus(object nObject)

  {

  AutoResetEvent autoEvent = (AutoResetEvent)nObject;



關(guān)鍵詞:

評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉