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...