How do you begin a storyboard from a different thread?
h1The Problem/h1 pI'm trying to play a StoryBoard from a different thread
but a 'System.InvalidOperationException' is thrown in WindowsBase.dll./p
pI have a custom Control, codeInfoBar/code, which has a StoryBoard to
close it and a codeSystem.Timers.Timer/code object to do so after several
seconds./p pSo, how do I call codeBeginStoryboard()/code from a different
thread?/p h1Error Message/h1 pThe exception thrown on
codeBeginStoryboard(sb)/code:/p pcodeAn exception of type
'System.InvalidOperationException' occurred in WindowsBase.dll but was not
handled in user code/code/p pcodeAdditional information: The calling
thread cannot access this object because a different thread owns
it./code/p h1My (simplified) Code/h1 precodeprivate int TimerSeconds;
private System.Timers.Timer t; public InfoBar() {
this.InitializeComponent(); TimerSeconds = 0; t = new
System.Timers.Timer(1000); t.Elapsed += t_Elapsed; } void t_Elapsed(object
sender, System.Timers.ElapsedEventArgs e) { if(TimerSeconds==3) {
t.Stop(); TimerSeconds = 0; System.Windows.Media.Animation.Storyboard sb =
(System.Windows.Media.Animation.Storyboard)FindResource(sbClose);
BeginStoryboard(sb); } else { TimerSeconds++; } } /code/pre
No comments:
Post a Comment