System.Timers.Timer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QnNtZW5nZW4=?=

    System.Timers.Timer

    I create the timer like this:

    StreamingTimer = new System.Timers.T imer();
    StreamingTimer. Elapsed += new
    System.Timers.E lapsedEventHand ler(StreamingPr oc);
    StreamingTimer. Interval = 1000;
    StreamingTimer. Enabled = true;
    StreamingTimer. Start();

    To dispose of the timer, I did this:
    StreamingTimer. Elapsed -= new
    System.Timers.E lapsedEventHand ler(StreamingPr oc);
    StreamingTimer. Dispose();

    Is that the correct way to close (dispose) a System.Timers.T imer?

    Do I have to deal with closing any thread in relation to the
    System.Timers.T imer?

    Thanks,
    Bob

  • Peter Duniho

    #2
    Re: System.Timers.T imer

    On Wed, 19 Mar 2008 14:38:00 -0700, Bsmengen
    <Bsmengen@discu ssions.microsof t.comwrote:
    I create the timer like this:
    >
    StreamingTimer = new System.Timers.T imer();
    StreamingTimer. Elapsed += new
    System.Timers.E lapsedEventHand ler(StreamingPr oc);
    StreamingTimer. Interval = 1000;
    StreamingTimer. Enabled = true;
    StreamingTimer. Start();
    Setting "Enabled" to "true" is synonymous with calling "Start()". It's
    redundant to do both.
    To dispose of the timer, I did this:
    StreamingTimer. Elapsed -= new
    System.Timers.E lapsedEventHand ler(StreamingPr oc);
    StreamingTimer. Dispose();
    >
    Is that the correct way to close (dispose) a System.Timers.T imer?
    Seems fine to me. There's not actually any need to remove your event
    handler, but it's not harmful to do so.
    Do I have to deal with closing any thread in relation to the
    System.Timers.T imer?
    No. You didn't create any thread, so there's no need for you to
    close/dispose any thread.

    Pete

    Comment

    Working...