Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating small application in wpf.
I want to add delay to the progressbar without any click mouse keyboard events.
I have kept one image as background for window.
So as soon as window loads image should display and after few seconds progress bar should display.

Whatever the delay I am giving its being applied to both image and progress bar.

Can anyone help me with it.?

What I have tried:

Private void onload(object sender RouteEventArgs e)
{
Int delay=2;
Task.delay(1000).wait();
}
Posted
Updated 24-Mar-22 20:57pm

1 solution

The problem is that both the picture display and the waiting are being done on the same thread - so the Paint event which actually displays the image isn't handled until after the wait is also continued.

There are several ways round this, but the simplest is to create a timer instead of waiting, and when its Tick event fires, display you progress bar.

However, if you are using a progress bar, then probably you are planning to do something that takes time and keeping the user informed - and you will have the same problem then as the progress bar will not be updated while your long running event is in progress.

So instead, use a BackgroundWorker[^] to perform your long running task, and use it's Progress facility to display and update your ProgressBar - your initial delay can slow that thread and the Progress event displays the Progress bar on the first update.
 
Share this answer
 
Comments
DivyaHal 1-Apr-22 13:22pm    
Thank you... Using background worker made everything simple.
OriginalGriff 1-Apr-22 14:48pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900