I have a WPF application targeting .NET 4.5.2 (but typically running under 4.6.1) and I've enabled spell checking on a couple of TextBoxes and DataGridTextColumns. Spell check is enabled via a style depending on what language the user has selected (we currently only support en). The application and system cultures are all set to en or en-US. I am not using any custom dictionaries.
Spellcheck is enabled via the following style:
<Style TargetType="TextBox">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Source={x:Static Properties:Settings.Default}, Path=Culture}"
Value="en" />
<Condition Binding="{Binding Source={x:Static diagnostics:Debugger.IsAttached}}"
Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="SpellCheck.IsEnabled"
Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
(We store the last selected application culture using the built-in ApplicationSettings object, and only save the most generic parent culture. If the user's system is set to "en-US", we'll just store "en" to simplify things.)
The TextBox is defined in a DataTemplate that is used for TreeViewItems, in case that makes any difference. Users are more likely to edit the TextBox rather than the DataGrid, so I suspect the issue is related to the TextBox.
On Windows 8 and 10, some users are experience a crash in the spell checker with the following stack trace:
System.ObjectDisposedException: Safe handle has been closed
at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
at System.Windows.Documents.WinRTSpellerInterop.ClearDictionaries(Boolean isDisposeOrFinalize)
at System.Windows.Documents.WinRTSpellerInterop.Dispose(Boolean disposing)
at System.Windows.Documents.WinRTSpellerInterop.Finalize()
I've searched Google, StackOverflow, and MSDN but can't find any reference to this issue. I don't know what my users are doing to trigger this case and I have been unable to reproduce it myself. My logs indicate they are not editing the spellcheck-enabled fields when this happens (in fact, the last editing they did was at least a minute or 2 prior to the exception). Does anyone have any ideas?