J
Jeff Gaines
Having read the thread on Application.DoEvents I wonder if anybody has any
thoughts on how to deal with a dice throwing routine? Currently I use:
private void ThrowDice()
// Sets dice numbers and draws dice
{
int count;
while (m_KeepRolling)
{
Random rnd1 = new Random(unchecked((int)DateTime.Now.Ticks));
Random rnd2 = new Random(~unchecked((int)DateTime.Now.Ticks));
for (count = JDice5Common.DICE1; count <= JDice5Common.DICE5; count++)
{
if (!m_DiceHeld[count])
{
m_DiceArray[count] = rnd2.Next(1, 7);
DrawDice(count);
Application.DoEvents();
}
}
}
for (count = JDice5Common.DICE1; count <= JDice5Common.DICE5; count++)
DrawDice(count);
}
m_KeepRolling is a module wide variable which is toggled by clicking the
'Throw Dice' button. Using Application.DoEvents() allows the dice to be
re-drawn with their new values and, I think, gives the OS a chance to
catch up.
What would other people do with this?
thoughts on how to deal with a dice throwing routine? Currently I use:
private void ThrowDice()
// Sets dice numbers and draws dice
{
int count;
while (m_KeepRolling)
{
Random rnd1 = new Random(unchecked((int)DateTime.Now.Ticks));
Random rnd2 = new Random(~unchecked((int)DateTime.Now.Ticks));
for (count = JDice5Common.DICE1; count <= JDice5Common.DICE5; count++)
{
if (!m_DiceHeld[count])
{
m_DiceArray[count] = rnd2.Next(1, 7);
DrawDice(count);
Application.DoEvents();
}
}
}
for (count = JDice5Common.DICE1; count <= JDice5Common.DICE5; count++)
DrawDice(count);
}
m_KeepRolling is a module wide variable which is toggled by clicking the
'Throw Dice' button. Using Application.DoEvents() allows the dice to be
re-drawn with their new values and, I think, gives the OS a chance to
catch up.
What would other people do with this?