WPF should clean up temp dictionary files it creates when the app sets Custom Dictionaries on text controls
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: (5.0.100-preview.2.20176.6/.NET 4.5.2+)
* Windows version: (Win 10 2004/Win8+`)
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
**Problem description:**
This is an adoption problem moving from Win7 to Win10
This does not repro on Win7 with the old spellcheck libraries.
when you add the same dictionary to every edit box in your app, a separate custom dictionary is registered for each one in %LocalAppData%\Temp\WPF, and causes perf issues, when we really just want all the edit boxes to use the same custom dictionary.
We can work around this issues by removing the code/xaml using WPF's custom dictionary support and instead using the Windows convention of putting in a *.dic file in %AppData%\Microsoft\Spelling with the app installer.
repro is as simple as...
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
StackPanel stackPanel = new StackPanel();
for (int i = 0; i < 100; i++)
{
var textBox = new TextBox();
textBox.Text = "Hello World.";
SpellCheck.SetIsEnabled(textBox, true);
var dictionaries = SpellCheck.GetCustomDictionaries(textBox);
dictionaries.Add(new Uri(@"pack://application:,,,/WpfDictPerf;component/CustomDictionary.lex"));
stackPanel.Children.Add(textBox);
}
this.Content = stackPanel;
}
**Actual behavior:**
1. App takes many seconds longer to open
2. a duplicate *.dic file is created for each textbox (even though the same spellchecker object is used, so one dictionary file applies to all TextBoxes)
3. *.dic files may be leaked and not deleted, ever causing the system to run out of disk space over time
**Expected behavior:**
1. App opens as fast as if no custom dictionaries are used
2. Only one new dictionary file is created
3. Orphaned Files are cleaned up next time the app is run
**Minimal repro:**
[WpfDictPerf.zip](https://github.com/dotnet/wpf/files/4761906/WpfDictPerf.zip)
1. Run attached WPFDictPerf
2. Open %LocalAppData%\Temp\WPF
3. Stop debugging
4. Run WPFDictPerf again
Contributor guide
Assessment
This issue has not been assessed yet.