Reputation: 10429
I have my code and problem like below
step1.Visible = true;
//step1 is visible if i retrun from here but if do some work like below than its not visible until the task is completed
Thread.Sleep(5000); // some opration here Thread.Sleep is just for example
step1.Visible = true;// step1 visible here not before thread going to sleep
Here I want to show the image for each step but first step image not showing if it's followed by some long running task any idea/trick show step1 in the case of Thread.Sleep(5000)?
Upvotes: 1
Views: 380
Reputation: 71
I'm not sure if I understand what do you want to do but first I will use those two function : Show() and Hide()
Now you have to work with Multi Threading and comunication between Threads
Hope this could help
Upvotes: 1
Reputation: 8007
Use Application.DoEvents()
before your Sleep (Any long running) Code.
Application.DoEvents() will processes all Windows messages currently in the message queue.
step1.Visible = true;
// Below 3 lines are not necessary. Use it only if DoEvents() doesn't work.
//step1.Invalidate();
//step1.Update();
//step1.Refresh();
// Will process the pending request of step1.Visible=true;
Application.DoEvents();
Thread.Sleep(5000);
step1.Visible = true;
Upvotes: 2
Reputation: 1032
You should use delegates or backgroundworker process to achieve that. you can get and idea from the link below.
Animated GIF in Windows Form while executing long process
Thanks
Upvotes: 0