Re: Storyboard .... again
It doesn't hang, it spins and uses a lot of cpu so it appears to hang.
In general, you never want to wait for a variable in an empty loop.
Re: Storyboard .... again
Btw, the file attachment download problem at code guru has been fix so you might want to zip up and post a sample solution that repros the issue.
Re: Storyboard .... again
Hi Arjay,
Apart from Zip, what is the correct way to approach this.
The Storyboard fires an iscompleted event, how do I wait for this to occur?
regards,
ger
Re: Storyboard .... again
Simple - rather than having a method contain code that happens before and after the wait, you create an iscometed event handler and put the after the wait code in there.
In general, in the main thread of a windows ui app, you should never write code that waits a significant amount of time (otherwise you will hang the ui).
Instead you write an event handler which allows the main ui thread to continue running freely and you achieve the same effect as a blocking call, but the ui thread remains responsive.
If you don't want the user to perform any actions, just disable some of the controls prior to creating the event handler and initiating the operation that will trigger the event.
This same concept is used in any Windows program ( win32, mfc, winforms, wpf, etc) to keep the ui responsive.
Re: Storyboard .... again
Hi,
Did it like this;
Code:
private void StoryBoardCompleted(object sender, EventArgs e)
{
board.Stop(this);
board.Remove(this);
this.Hide();
COD01Window COD01 = new COD01Window();
COD01.ShowDialog();
Image_COD1.Visibility = Visibility.Visible;
this.Show();
}
one small item, when the same button is pressed again in the main window, I have to close the COD01 window 2 times.
and so on.
in the COD01 window I use Close();
regards,
ger
Re: Storyboard .... again
Solve the two problems separately. That is, get the popup modal for. Working before putting thst code in an event handler.
Also, respond to my suggestions directly. Tell me if my suggestions have worked or have not and so on.
I don't want to take the time to help, if you can't take the time to try the suggestions or respond to what I've written.
Re: Storyboard .... again
hi Arjay,
did what you suggested;
put the after wait code in the completed handler.
Also tested the window issue non an separate test button
separate they work fine now.
But if I put the create and show window in the event handler, the dispose of the window is not done correctly.
regards,
Ger
Re: Storyboard .... again
Check which thread the event handler executes in. Is it the same as the main ui thread?
Re: Storyboard .... again
Hi All,
Solved the problem.
Thanks to the hint of Arjay on threads.
I'm using async and await
like this;
Code:
private async void COD1_MouseUp(object sender, MouseButtonEventArgs e)
{
board = (Storyboard)TryFindResource("Storyboard1");
Image_COD1.Visibility = Visibility.Hidden;
board.Begin(this, true);
await Task.Delay(2000); // time it takes the animation to finish, 2 seconds
board.Stop(this);
this.Hide();
COD01Window COD01 = new COD01Window();
COD01.ShowDialog();
Image_COD1.Visibility = Visibility.Visible;
this.Show();
}
PS, you have to set the button(s) to IsEnabled to false;
until the await Task.Delay has finished
regards,
Ger