I have a function that renders roughly 100-200 images on a canvas, ever since moving my applications resources to an archive and reading them in from memory i am getting a white screen for a second or so whilst it renders the images.
This wasnt happening when i was using a flat file system but i would like to keep the archive system as it has its easier to manage. What would be the best way of handling the more intensive functions like this whilst decreasing the white screen or eliminating it entirely.
I have tried utilising async but that makes it so you can see each of the images being rendered and i dont want that as i would like it to happen before the window is shown.
The code for the intensive function is as follows...
internal static void RenderStars(Canvas canvas, int density = 200)
{
List<string> getStars = Resource.GetFiles("images/scene/stars", "star_*.png");
var random = new Random();
for (int x = 0; x < density; x++)
{
string starImage = getStars[random.Next(0, getStars.Count)];
int starSize = random.Next(1, 10);
int starOpacity = random.Next(10, 50);
int starX = random.Next(0, (int) canvas.ActualWidth);
int starY = random.Next(0, (int) canvas.ActualHeight);
var star = new Image
{
Name = (x < 10) ? "Star_0" + x : "Star_" + x,
Source = Core.StreamImage(starImage),
Height = starSize,
Width = starSize,
Opacity = (double) starOpacity/100
};
canvas.Children.Add(star);
Canvas.SetLeft(star, starX);
Canvas.SetTop(star, starY);
Panel.SetZIndex(star, 0);
}
}
Any help would be great, thanks so much :)