LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Gtk# Image Pixbuf freeze (https://www.linuxquestions.org/questions/programming-9/gtk-image-pixbuf-freeze-529725/)

spoody_goon 02-16-2007 03:51 PM

Gtk# Image Pixbuf freeze
 
Using monodevelop v 0.12 gtk-sharp 2.0.
The program is a simple Yahtzee game it freezes when changing the dice images. The big catch to the code below is it works if I use the checkboxes to stop the images from changing for the first roll. After that it will work fine.

Code:

protected System.Timers.Timer  mTimer = new System.Timers.Timer();
               
// load the dice images into an array
DiceArray[0] = Gdk.Pixbuf.LoadFromResource("dice1.png");
DiceArray[1] = Gdk.Pixbuf.LoadFromResource("dice2.png");
DiceArray[2] = Gdk.Pixbuf.LoadFromResource("dice3.png");
DiceArray[3] = Gdk.Pixbuf.LoadFromResource("dice4.png");
DiceArray[4] = Gdk.Pixbuf.LoadFromResource("dice5.png");
DiceArray[5] = Gdk.Pixbuf.LoadFromResource("dice6.png");

when the roll button is pushed it starts the gtk.timer

Code:

this.mTimer.Enabled = true;
this.mTimer.AutoReset = true;
this.mTimer.Interval = 1;
this.mTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.mTimer_Tick);
this.mTimer.Start();

then the image widget is assinged an image from the pixbuf array via a random number

Code:

Random random = new Random();
if((lblHold1.State.ToString() != "Active")&& (mTimer.Interval < 34))
    Dice1.Pixbuf  = DiceArray[random.Next(0, 5)];
                                                       
if((lblHold2.State.ToString() != "Active")&& (mTimer.Interval < 29))
    Dice2.Pixbuf = DiceArray[random.Next(0, 5)];
                                               
if((lblHold3.State.ToString() != "Active")&& (mTimer.Interval < 32))
    Dice3.Pixbuf = DiceArray[random.Next(0, 5)];
                                               
if((lblHold4.State.ToString() != "Active")&& (mTimer.Interval < 25))
  Dice4.Pixbuf = DiceArray[random.Next(0, 5)];
                                               
if((lblHold5.State.ToString() != "Active")&& (mTimer.Interval < 22))
  Dice5.Pixbuf = DiceArray[random.Next(0, 5)];
                                               
mTimer.Interval = mTimer.Interval + 1;
if(mTimer.Interval > 35)
{
  // destroy the timer at the end of the roll cycle
  mTimer.Dispose();
}



All times are GMT -5. The time now is 02:42 PM.