Aym*_*lah 0 c# wpf window exception storyboard
我正在使用WPF,在我的主窗口上,每当我尝试做任何事情时它都会给我这个错误"调用线程无法访问此对象,因为另一个线程拥有它." 这些例如,
this.Visibility = Visibility.Visible
((Storyboard)this.FindResource("HideWindow")).Begin()
Run Code Online (Sandbox Code Playgroud)
我真的不知道那是什么,并且在大量需要帮助时我无法执行我的代码的第一行.更多信息:我无法打开另一个窗口,给我的线程不是STA错误
LoginWindow objLoginWindow = new LoginWindow();
objLoginWindow.ShowDialog();
objLoginWindow = null;
Run Code Online (Sandbox Code Playgroud)
这是例外.
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=The calling thread cannot access this object because a different thread owns it.
Source=WindowsBase
StackTrace: at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Menupedia.LoadingWindow.OpenNewWindow() in c:\Users\xxxx\Desktop\menupedia\Menupediaa\Menupedia\LoadingWindow.xaml.cs:line 51
at Menupedia.LoadingWindow.TimeElapsed(Object sender, ElapsedEventArgs e) in c:\Users\xxxx\Desktop\menupedia\Menupediaa\Menupedia\LoadingWindow.xaml.cs:line 39
at System.Timers.Timer.MyTimerCallback(Object state)
Run Code Online (Sandbox Code Playgroud)
您的堆栈跟踪显示您使用了System.Timers.Timer.ElapsedTimer 的处理程序在后台线程中调用,后者不允许直接访问UI元素.您必须调用Dispatcher.Invoke或Dispatcher.BeginInvoke访问Elapsed处理程序中的UI元素.
但是,通过a替换Timer可能更容易System.Windows.Threading.DispatcherTimer,它具有Tick在UI线程中调用的事件,因此允许安全访问UI元素.
| 归档时间: |
|
| 查看次数: |
632 次 |
| 最近记录: |