0

Firstly, I would like to thank you for this fine site, you have managed to help me to develop confidence in programming and teaching me each day how to be better at what I love. This is my first post here, sorry for any mistakes in the post!

Plot:
I have created an app to display the time and additional information on a smart tv screen.
At startup, the MainWindow shows a custom digital clock with a progressbar to show how many percent is done from the current shift, secondly it displays an image for 20 seconds about the Plants Efficiency (GlobalEff.png). I am using /Pages to switch between the clock and the image: Every Minute's 40th second it switches to the image, and at 00 it goes back to being a clock.

Issue:
This app should run 24/7 without ever having to restart, let alone rebuilding it. Sadly the "GlobalEff.png" will not update under runtime no matter what. I recieve a new "GlobalEff.png" each day from another department.
I store it as 'App/Resources/GlobalEff.png' It keeps displaying the "default" image, the one that was built with. Not even a normal restart helps. I have to rebuild it entirely.

Research:
WPF Image Dynamically changing Image source during runtime

I have tried to develop this into my solution plus a lot of iterations, all it does that it loads the current "GlobalEff.png" at build, but if I overwrite the imagefile manualy it doesn't change.

WPF Image Caching

Same thing, it loads the current GlobalEff.png

Binding an Image in WPF MVVM

I also tried {binding imagepath}, with same result.

This loads current image at building too, but not refreshing at runtime.:

BitmapImage bmp = new BitmapImage();
 bmp.BeginInit();
 bmp.CacheOption = BitmapCacheOption.None;
 bmp.UriCachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache);
 bmp.CacheOption = BitmapCacheOption.OnLoad;
 bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
 bmp.UriSource = new Uri(@"pack://application:,,,/Resources/GlobalEff.png", UriKind.Absolute);
 bmp.EndInit();
 ImgEff.Source = bmp;

My current code:

public GlobalProductionEfficiency()
{
    InitializeComponent();

    this.DataContext = this;
    ImgEff.Source = new BitmapImage(new Uri(@"\Resources\GlobalEff.png", UriKind.Relative));
}

XAML:

<Grid Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Center">
        <Image x:Name="ImgEff" />
    </StackPanel>
</Grid>

As you can see, I have nothing fancy in the code, this loads the current image file but not following any changes. I did this to cleanup all the iterations of URI paths, BitmapImage settings, etc.

My Goal would be to drop the "old" cached picture and display the "new" GlobalEff.png without the need of stopping the program nor rebuilding it. What am I missing?
How can I force delete image cache, when '.IgnoreImageCache' is not doing the trick?

Thank you for reading, and thank you in advance for any help or suggestion!

  • You must not load the image from an assembly resource file when you want to be able to replace it at runtime. Instead, load it from an absolute or relative file path. – Clemens Mar 18 '22 at 09:53
  • Hi @Clemens, thank you for your answer. I deleted the image from the Project, also added a copy to a test path e.g: H:/GlobalEff.png. It still won't refresh in runtime, only at rebuild/build. – Zsolt_B Mar 18 '22 at 12:21
  • It will refresh when you reload it as shown in the answer to the duplicate question. – Clemens Mar 18 '22 at 12:30
  • I tried both code just now, there is still no update done. Interestingly, if I delete the image from destination, I get an ex. error with 'file missing', so the code IS looking for the file. – Zsolt_B Mar 18 '22 at 12:53

0 Answers0