我正在咨询的公司有特定的业务要求,某些WPF Windows的每个实例必须拥有自己的UI线程,并且不能在应用程序是共享由.NET Framework创建的默认UI线程第一次加载。Telerik RadDocking的线程问题
从编码的角度来看,这很容易实现,并且运行良好,直到在xaml中引入Telerik RadDocking控件。我已经直接从示例代码复制并粘贴了xaml表单telerik的RadDocking示例,而无需修改它。当应用程序启动时,WindowWithTelerikDockingFromExample的两个实例一开始就没有问题地加载,事实上,窗口的第二个实例(标题为“独立UI线程上的窗口...”)是可操作的并且工作正常,“MainWindow” 。直到激活第二个窗口,然后激活主窗口,然后切换回第二个窗口,抛出以下异常:
“调用线程无法访问此对象,因为不同的线程拥有它。”
为
'c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Docking\Docking\Parts\AutoHideArea.cs'. Checksum: MD5 {3e 1e cd 2a 97 89 30 7e c9 1c 28 c2 28 13 aa e9}
The file 'c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Docking\Docking\Parts\AutoHideArea.cs' does not exist.
Looking in script documents for 'c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Docking\Docking\Parts\AutoHideArea.cs'...
Looking in the projects for 'c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Docking\Docking\Parts\AutoHideArea.cs'.
The file was not found in a project.
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Docking\Docking\Parts\AutoHideArea.cs.
The debugger could not locate the source file 'c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Docking\Docking\Parts\AutoHideArea.cs'.
这里找到源是我的代码:
App.xaml.cs:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
this.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose;
// Init the application's main window...
var mainWindow = new WindowWithTelerikDockingFromExample();
mainWindow.Title = "Main Window";
this.MainWindow = mainWindow;
mainWindow.Show();
// init another instance of the window with the telerik docking, on a seperate UI thread...
var thread = new Thread(() =>
{
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));
var window2 = new WindowWithTelerikDockingFromExample();
window2.Title = "Window on seperate UI Thread...";
window2.Show();
System.Windows.Threading.Dispatcher.Run();
window2.Closed += (s2, e2) =>
{
window2.Dispatcher.InvokeShutdown();
};
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
base.OnStartup(e);
}
}
WindowWithTelerikDockingFromExample.xaml:
<Window x:Class="TelerikDockingThreadIssueExample.WindowWithTelerikDockingFromExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="Window with xaml copy and pasted from Telerik example" Height="300" Width="300">
<Grid>
<telerik:RadDocking BorderThickness="0" Padding="0">
<telerik:RadDocking.DocumentHost>
<telerik:RadSplitContainer>
<telerik:RadPaneGroup>
<telerik:RadDocumentPane Header="Document 1" Title="Document 1" />
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
</telerik:RadDocking.DocumentHost>
<telerik:RadSplitContainer InitialPosition="DockedLeft">
<telerik:RadPaneGroup>
<telerik:RadPane Header="Pane Left 1" IsPinned="False">
<TextBlock Text="Pane Left 1" />
</telerik:RadPane>
<telerik:RadPane Header="Pane Left 2" IsPinned="False">
<TextBlock Text="Pane Left 2" />
</telerik:RadPane>
<telerik:RadPane Header="Pane Left 3" IsPinned="False">
<TextBlock Text="Pane Left 3" />
</telerik:RadPane>
<telerik:RadPane Header="Pane Left 4" IsPinned="False">
<TextBlock Text="Pane Left 4" />
</telerik:RadPane>
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
<telerik:RadSplitContainer InitialPosition="DockedRight">
<telerik:RadPaneGroup>
<telerik:RadPane Header="Pane Right 1" IsPinned="False">
<TextBlock Text="Pane Right 1" />
</telerik:RadPane>
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
<telerik:RadSplitContainer InitialPosition="DockedBottom">
<telerik:RadPaneGroup>
<telerik:RadPane Header="Pane Bottom 1" IsPinned="False">
<TextBlock Text="Pane Bottom 1" />
</telerik:RadPane>
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
</telerik:RadDocking>
</Grid>
</Window>
任何想法?
不幸的是,该错误仍然是开放的,“不计划”,所以我们不会在2013年Q3 SP1修复。 – Amer