AddDictionary has long load-time

4 posts, 0 answers
  1. Peter
    Peter avatar
    95 posts
    Member since:
    Mar 2009

    Posted 22 Oct 2012 Link to this post

    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
  2. Andrew
    Admin
    Andrew avatar
    140 posts

    Posted 26 Oct 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Peter
    Peter avatar
    95 posts
    Member since:
    Mar 2009

    Posted 29 Oct 2012 Link to this post

    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.
  5. Andrew
    Admin
    Andrew avatar
    140 posts

    Posted 01 Nov 2012 Link to this post

    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.

Back to Top