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