Browse Source

Fix #311 - AvalonEdit cannot be used in WPF application with multiple UI threads.

4.x
Daniel Grunwald 11 years ago
parent
commit
99747ac0fc
  1. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj
  2. 43
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/MultipleUIThreads.cs
  3. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.xaml

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj

@ -80,6 +80,7 @@ @@ -80,6 +80,7 @@
<Compile Include="Editing\ChangeDocumentTests.cs" />
<Compile Include="Editing\TextSegmentReadOnlySectionTests.cs" />
<Compile Include="Highlighting\HtmlClipboardTests.cs" />
<Compile Include="MultipleUIThreads.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Document\CollapsingTests.cs" />
<Compile Include="Document\HeightTests.cs" />

43
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/MultipleUIThreads.cs

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Threading;
using System.Windows;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit
{
[TestFixture]
public class MultipleUIThreads
{
Exception error;
[Test]
public void CreateEditorInstancesOnMultipleUIThreads()
{
Thread t1 = new Thread(new ThreadStart(Run));
Thread t2 = new Thread(new ThreadStart(Run));
t1.SetApartmentState(ApartmentState.STA);
t2.SetApartmentState(ApartmentState.STA);
t1.Start();
t2.Start();
t1.Join();
t2.Join();
if (error != null)
throw new InvalidOperationException(error.Message, error);
}
[STAThread]
void Run()
{
try {
var window = new Window();
window.Content = new TextEditor();
window.Show();
} catch (Exception ex) {
error = ex;
}
}
}
}

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.xaml

@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
</Setter>
</Style>
<Style TargetType="{x:Type editing:TextArea}">
<Style TargetType="{x:Type editing:TextArea}" x:Shared="False">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="SelectionBrush">
<Setter.Value>

Loading…
Cancel
Save