Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Passing Information to Timer.Elapsed Method

Passing Information to Timer.Elapsed Method

Scheduled Pinned Locked Moved C#
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ezazazel
    wrote on last edited by
    #1

    Hi guys! I have a question concerning the Timer Elapse Event and the invoked Method. Is it possible to add an object to the timer which is passed to the Method? Something like this:

    public Timer MouseHooverTimer
    {
    get
    {
    if (mouseHooverTimer == null)
    {
    mouseHooverTimer = new Timer(2000);
    mouseHooverTimer.Elapsed += new ElapsedEventHandler(mouseHooverTimer_Elapsed);
    }
    return mouseHooverTimer;
    }
    }

    private void StartTimer(object information)
    {
    mouseHooverTimer.Start(); <== HERE ADD THE OBJECT information
    }

    void mouseHooverTimer_Elapsed(object sender, ElapsedEventArgs e)
    {
    //HERE USE THE OBJECT information
    }

    Thanks in advance!

    P C 2 Replies Last reply
    0
    • E ezazazel

      Hi guys! I have a question concerning the Timer Elapse Event and the invoked Method. Is it possible to add an object to the timer which is passed to the Method? Something like this:

      public Timer MouseHooverTimer
      {
      get
      {
      if (mouseHooverTimer == null)
      {
      mouseHooverTimer = new Timer(2000);
      mouseHooverTimer.Elapsed += new ElapsedEventHandler(mouseHooverTimer_Elapsed);
      }
      return mouseHooverTimer;
      }
      }

      private void StartTimer(object information)
      {
      mouseHooverTimer.Start(); <== HERE ADD THE OBJECT information
      }

      void mouseHooverTimer_Elapsed(object sender, ElapsedEventArgs e)
      {
      //HERE USE THE OBJECT information
      }

      Thanks in advance!

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      No, just use a field. Or derive your own timer class that will do it.

      E 1 Reply Last reply
      0
      • P PIEBALDconsult

        No, just use a field. Or derive your own timer class that will do it.

        E Offline
        E Offline
        ezazazel
        wrote on last edited by
        #3

        Thank you!

        1 Reply Last reply
        0
        • E ezazazel

          Hi guys! I have a question concerning the Timer Elapse Event and the invoked Method. Is it possible to add an object to the timer which is passed to the Method? Something like this:

          public Timer MouseHooverTimer
          {
          get
          {
          if (mouseHooverTimer == null)
          {
          mouseHooverTimer = new Timer(2000);
          mouseHooverTimer.Elapsed += new ElapsedEventHandler(mouseHooverTimer_Elapsed);
          }
          return mouseHooverTimer;
          }
          }

          private void StartTimer(object information)
          {
          mouseHooverTimer.Start(); <== HERE ADD THE OBJECT information
          }

          void mouseHooverTimer_Elapsed(object sender, ElapsedEventArgs e)
          {
          //HERE USE THE OBJECT information
          }

          Thanks in advance!

          C Offline
          C Offline
          carlecomm
          wrote on last edited by
          #4

          Hi, of course, you can add an object to the timer. but you must recognize that 'timer Thread' is not the same to 'main Thread', so after you create the object in 'timer thread', if you use it in 'main thread', will throw an error.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups