0

I am trying to hide something in the .designer.cs page of a windows form.

I want it to run off the ui thread, and update the background of the form to show a gif (totally PG).

This is all I have been able to come up with so far, but something must be fundamentally flawed because it doesn't work.

Tips?

            #region importantthigns
        if (System.DateTime.Now.Hour > 15)
        {
            System.Drawing.Image gifImg = global::STAMPS.Properties.Resources.fredleaveswork;
            System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(gifImg.FrameDimensionsList[0]);
            this.BackgroundImage = gifImg;
            int frameCount = gifImg.GetFrameCount(dimension);
            object locker = new object();
            new System.Threading.Thread(() =>
         {

             while (true)
             {
                 try
                 {
                     for (int x = 0; x < frameCount; x++)
                     {
                         System.Threading.Thread.Sleep(300);
                         if (this.InvokeRequired)
                         {
                             this.Invoke(new System.Action(
                                  () =>
                                  {
                                      lock (locker)
                                      {
                                          gifImg.SelectActiveFrame(dimension, x);
                                          this.BackgroundImage = gifImg;
                                      }

                                  }));
                         }
                         else
                         {
                             gifImg.SelectActiveFrame(dimension, x);
                             this.BackgroundImage = gifImg;
                         }

                     }
                 }
                 catch (System.Exception)
                 {
                     //stealth mode
                 }

             }
         }).Start();
        }
        #endregion

Update! - I found that if I minimize and (unminimize?) the image is working as expected, kinda. I think I just need to reload the page or something...

Asymptote
  • 13
  • 6
  • using this to simulate the minimize...http://stackoverflow.com/q/2665900/7474080 – Asymptote Apr 26 '17 at 16:00
  • now to fix the flicker... – Asymptote Apr 26 '17 at 16:42
  • `DoubleBuffer`! – TaW Apr 26 '17 at 17:53
  • I tried that, didn't seem to work. I expect its because my refresh rate is so low. I gather there is the ability to not create a void of colour as the child controls redraw themselves, but its to much work to go into each of them and create my own user controls. I found that tile mode reduces it alot, trying to resize the image so tile mode covers the entire form – Asymptote Apr 26 '17 at 20:59
  • Ended up fixing it with http://stackoverflow.com/a/10038782/7474080, although not to happy that I had to use an event – Asymptote Apr 26 '17 at 21:17
  • @Asymptote: Events are often a common way of fixing WinForms bad functionality, I simply got used to it, and it works, sometimes with collateral effects like with drugs ;-) Maybe double buffering together with async could solve the issue... – sɐunıɔןɐqɐp Sep 13 '19 at 09:51

0 Answers0