I've made a graphic simulation with a timer. But now I want to stop the simulation (but not disappear) only freeze the simulation.

I've already tried to use a do-while-loop but then the application crashes.
I've also tried to use a if-loop and in the loop set the length (that the application have to drawn) to zero but it doesn't freeze.
I've also tried to use in a if-loop, to call another function which doesn't do anything but this doesn't freeze the application.
Also I did this in a do-while-loop but then it crashes.

Does someone knows an answer and perhaps knows an example that I can understand what you're trying to say.

8 Years
Discussion Span
Last Post by LizR

Whatever your "graphic simulation" does, it obviously should call an "update" function and a "draw" function.. When you want it to "freeze" just stop the updates and continue drawing it at its current state



Thx for your reply. But I don't get in, I think.
Here is my code. What do you think I should do?

private void pictureBox1_Paint(object sender, PaintEventArgs e)
          // opvragen van de burst die momenteel gedaan is
            // dit kan via een methode in de Controller te steken
            // die controlleerd welke knop (FCFS-SJF) ingedrukt werd
            // in deze klasse wordt er dan gekeken naar de eindeburst
            // Dat moet dan doorgestuurd worden naar hier.

            Graphics g = e.Graphics;
            String algoritme = cmbSchedule.SelectedItem.ToString();
            int burstlengte = 0;
            switch (algoritme)
                case "FCFS": //burstlengte = Controller.GetInstance(ProcessList).Simulatie(ProcessList[0].lijstvanBursts[0]);
                        burstlengte = Controller.GetInstance(ProcessList).Hoeveelburst(ProcessList[0].lijstvanBursts[0].Lengte);
                        foreach (Proces p in ProcessList)
                            foreach (Burst b in p.lijstvanBursts)
                                if (Controller.GetInstance(ProcessList).Teller > p.PAankomst + b.Lengte)
                                    // No simulation anymore
                                    burstlengte = 0;                                   

                                //    eind();
                                //} while (Controller.GetInstance(ProcessList).Teller > (p.PAankomst + b.Lengte) || Controller.GetInstance(ProcessList).Teller == (p.PAankomst + b.Lengte));
                case "SJF": //burstlengte = SJF.getInstance().GeordendeLijst[0].lijstvanBursts[0].Lengte;
                    //burstlengte = Controller.GetInstance(ProcessList).Hoeveelburst(SJF.getInstance().GeordendeLijst[0].lijstvanBursts[0].Lengte);
            // Laat de simulatie niet verder gaan als de burst gedaan is
            //if (Controller.GetInstance(ProcessList).Teller > burstlengte + ProcessList[0].PAankomst)
            //    burstlengte = 0;

            //int burstlengte = Controller.GetInstance(ProcessList).Simulatie(ProcessList[0].lijstvanBursts[0]);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle rect = new Rectangle(20, 20, burstlengte , 100);
            Pen redPen = new Pen(Color.Red, 3);
            g.FillRectangle(Brushes.Red, 25, 20, burstlengte , 100);
            //Graphics g = e.Graphics;
            //foreach (Proces p1 in lbProcessName.Items)
            //    foreach (Burst b in p1.lijstvanBursts)
            //    {
            //        int burstlengte = Controller.GetInstance(ProcesList).Simulatie(b);
            //        g.SmoothingMode = SmoothingMode.AntiAlias;
            //        Rectangle rect = new Rectangle(20, 20, burstlengte * 2, 100);

            //        Pen redPen = new Pen(Color.Red, 3);
            //        g.FillRectangle(Brushes.Red, 25, 20, burstlengte * 2, 100);
            //    }


Theres a mix of decision making and displaying going in in that procedure, Id suggest you split the code so that all the variables needed to draw are private to the class, and you have an update procedure that sets them, and then the draw procedure just draws them, then when you need to "pause" the displaying of the simulation, you just dont run the update and the last values are used.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.