I am using How do I get an animated gif to work in WPF? in my program.
Initially in XAML, I set Visibility="Hidden"
and
use animateImage.Visibility = Visibility.Visible;
when I want the image to display.
After dispalying the image, I run a process. However, as soon as the process starts, the animation pauses. I wonder why is it doing that?
I was thinking to create a new thread and run GIF in the thread, and close the thread when process is completed.
EDIT
Code for the process that I am running. I want the animation to play during the GPUpdate.
ExecProc("gpupdate", "/force");
private static bool ExecProc(string file, string arg)
{
bool flag = true;
try
{
//Create a new process info structure.
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = file;
pInfo.CreateNoWindow = true;
pInfo.Arguments = arg;
pInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process ps = new Process();
ps.StartInfo = pInfo;
ps.Start();
//Wait for the process to end.
ps.WaitForExit();
}
catch (Exception e)
{
writeLog("Error: " + e + " running " + file + " " + arg);
flag = false;
}
return flag;
}
Mohammad Dehghan was really helpful and got me in the right direction. However, I was looking something slightly different, so posting what ended up with.
It goes and executes the process while other stuff is keep running in the background.
animateImage.Visibility = Visibility.Visible;
await Task.Run(() =>
{
// Process goes here
});
animateImage.Visibility = Visibility.Hidden;