This is a migrated thread and some comments may be shown as answers.

AddDictionary has long load-time

3 Answers 39 Views
SpellChecker
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 23 Oct 2012, 01:05 AM
Hi,

Using JustTrace I've determined that a window that is loaded is most time-consuming in the AddDictionary method of the RichTextBox SpellChecker. I would like to call this method in a background thread so that it doesn't hang the application. Obviously I can't use BackgroundWorker because making modifications to a UI control. So I'm after other options for preventing the window from hanging? Perhaps this question is more general than the SpellChecker forum subfolder, but the problem has started from here :)

Thanks

3 Answers, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 26 Oct 2012, 07:39 AM
Hello Peter,

BackgroundWorker cannot access objects that are UI elements and are owned by the main UI thread. Every other object you can access using a Dispatcher. So here is some code for you to try:

private void OnButtonClick(object sender, RoutedEventArgs e)
        {
            DocumentSpellChecker documentSpellChecker = this.editor.SpellChecker as DocumentSpellChecker;
            BackgroundWorker backgroundWorker = new BackgroundWorker();
            backgroundWorker.DoWork += DoWork;
            backgroundWorker.RunWorkerAsync(documentSpellChecker);
        }
 
        void DoWork(object sender, DoWorkEventArgs e)
        {
            DocumentSpellChecker dsc = e.Argument as DocumentSpellChecker;
            Dispatcher.BeginInvoke((Action)(() =>
                {
                    dsc.AddDictionary(new RadEn_USDictionary(), CultureInfo.InvariantCulture);
                }));
        }
The above code shows how to load a dictionary using a BackgroundWorker and a Dispatcher.
Kind regards,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Peter
Top achievements
Rank 1
answered on 29 Oct 2012, 07:03 AM
Thanks Andrew, I'm glad to have learnt that.
Unfortunately it doesn't seem to have sped up the window loading. JustTrace is still telling me the InitializeComponent is the most time intensive method, the only difference is that AddDictionary is no longer the most time intensive sub-method in it and RichTextBoxChangedCallback is now the top method, but it is a much lower time percentage. I'm not sure what other tips you can offer me here, but anything to speed up the window load would be appreciated.
0
Andrew
Telerik team
answered on 01 Nov 2012, 04:40 PM
Hello Peter,

We would really appreciate it if you open a support ticket and attach a project illustrating the issue. Furthermore, please specify what your load time in milliseconds is and what the time you expect is. This would help us a lot in investigating the issue.

Regards,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
SpellChecker
Asked by
Peter
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Peter
Top achievements
Rank 1
Share this question
or