locked
Asynchronous code completion in Visual Studio RRS feed

  • Question

  • I am developing Visual Studio extension and one of features is JavaScript code completion. I implemented ICompletionSource and other stuff base on that article: https://msdn.microsoft.com/en-us/library/ee372314.aspx. Everything works, but in my real implementation, the act of getting completions is slow (it's handled by another process). It causes that UI is frozen for a while and it has negative impact on user experience. Is there any way how to made code completion asynchronous?
    Tuesday, March 1, 2016 3:55 PM

All replies

  • Hi Miroslav Grela,

    >>Is there any way how to made code completion asynchronous?

    Try to make TriggerCompletion asynchronous. Change following code.

    this.TriggerCompletion();

    To

    Thread t = new Thread(new ThreadStart(() => { this.TriggerCompletion(); }));
    t.Start();
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 3, 2016 2:45 AM
  • Hi Li Wang,

    thank you for your suggestion. I tried call TriggerCompletion in new thread as you suggested, but I got following exception: 

    System.InvalidOperationException: The calling thread must be STA, because many UI components require this.

    Then I tried to call it this way:

    Thread t = new Thread(() => TriggerCompletion());
    t.SetApartmentState(ApartmentState.STA);
    t.Start();

    but then I got this exception:

    System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it;   at System.Windows.Threading.Dispatcher.VerifyAccess();

    Then I tried this:

    Thread t = new Thread(() =>
        Application.Current.Dispatcher.Invoke(() => TriggerCompletion()));
    t.SetApartmentState(ApartmentState.STA);
    t.Start();

    This code didn't throw any exception, but it still works synchronously and blocks UI.

    Any other suggestions?


    Tuesday, March 8, 2016 8:53 AM
  • Hi Miroslav,

    I have no idea, maybe following thread could give you some opinions。

    http://stackoverflow.com/questions/25487920/how-do-i-asynchronously-update-completion-results-in-an-icompletionsource

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 25, 2016 8:32 AM