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. Thread Sleeping using an enum

Thread Sleeping using an enum

Scheduled Pinned Locked Moved C#
helpcsharpcomquestion
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.
  • M Offline
    M Offline
    MStanbrook
    wrote on last edited by
    #1

    I'm having a bit of trouble with SLEEPing a thread in c#. I have the following enum used to control how long the thread should sleep: public enum RefreshRate{ fast = 100, medium = 500, slow = 1000 } but the line: oThread.Sleep(RefreshRate); Generates the following error: Argument '1': cannot convert from 'RefreshRate' to 'int' The default type for an enum is INT, so I'm not sure what's causing the problem. Anyone have any ideas? TIA. Mike Stanbrook mstanbrook@yahoo.com

    D 1 Reply Last reply
    0
    • M MStanbrook

      I'm having a bit of trouble with SLEEPing a thread in c#. I have the following enum used to control how long the thread should sleep: public enum RefreshRate{ fast = 100, medium = 500, slow = 1000 } but the line: oThread.Sleep(RefreshRate); Generates the following error: Argument '1': cannot convert from 'RefreshRate' to 'int' The default type for an enum is INT, so I'm not sure what's causing the problem. Anyone have any ideas? TIA. Mike Stanbrook mstanbrook@yahoo.com

      D Offline
      D Offline
      David Stone
      wrote on last edited by
      #2

      It's still an enum of type RefreshRate. What you need to do is put:

      oThread.Sleep((int)RefreshRate.fast);


      I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past. -Chris Maunder Microsoft has reinvented the wheel, this time they made it round. -Peterchen on VS.NET

      N 1 Reply Last reply
      0
      • D David Stone

        It's still an enum of type RefreshRate. What you need to do is put:

        oThread.Sleep((int)RefreshRate.fast);


        I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past. -Chris Maunder Microsoft has reinvented the wheel, this time they made it round. -Peterchen on VS.NET

        N Offline
        N Offline
        Nick Parker
        wrote on last edited by
        #3

        David Stone wrote: oThread.Sleep((int)RefreshRate.fast); You don't necessarily need to cast the enum; this should work explicitly when you identify the base type of the enum:

        public enum RefreshRate : int
        {
        fast = 100,
        medium = 500,
        slow = 1000
        }

        oThread.Sleep(RefreshRate.fast);

        :) Nick Parker
        May your glass be ever full. May the roof over your head be always strong. And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing


        D 1 Reply Last reply
        0
        • N Nick Parker

          David Stone wrote: oThread.Sleep((int)RefreshRate.fast); You don't necessarily need to cast the enum; this should work explicitly when you identify the base type of the enum:

          public enum RefreshRate : int
          {
          fast = 100,
          medium = 500,
          slow = 1000
          }

          oThread.Sleep(RefreshRate.fast);

          :) Nick Parker
          May your glass be ever full. May the roof over your head be always strong. And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing


          D Offline
          D Offline
          David Stone
          wrote on last edited by
          #4

          That, and I just noticed that he was doing oThread.Sleep(RefreshRate); He wasn't specifying a value at all.


          I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past. -Chris Maunder Microsoft has reinvented the wheel, this time they made it round. -Peterchen on VS.NET

          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