"Visual Studio stopped responding for 12 seconds, uninstalling extension might help" getting this message on installing VSIX and on opening the project. How to remove delay?

Mekala Meghana 20 Reputation points
2024-03-29T14:10:34.66+00:00

When trying to add existing/New item, getting error message like "Cannot access to disposed object". To resolve that making the method to run asynchronously and it got resolved, but due to that getting some delay in extension after opening the project.In this method first getting "Cannot access to disposed object" error.

private void ProjectItemsEvents_AfterAddProjectItems ()

{

}

After making it to asynchronous method, getting delay in extension.

private async void asynchronous ()

{

await System.Threading.Tasks.Task.Run(() => ProjectItemsEvents_AfterAddProjectItems();

}

Kindly help in removing the delay

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,608 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,251 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 48,281 Reputation points
    2024-03-29T15:04:16.9766667+00:00

    Are you building an extension for VS? Note that it is unlikely that simply making something async is solving the underlying disposed issue. More likely it is just kicking it down the (time) road so you aren't seeing it right now. But as with all timing issues it is going to reappear at random. The specific error you're getting indicates you are accessing something after it has already been cleaned up which means you have a lifetime management issue somewhere. Without seeing exactly where the error is occurring then it is hard to say what.

    In terms of the delay, you have added an async method but it is unclear where it is being called from. Within the async method you are async calling your original method. Honestly this isn't remotely recommended. Making a sync method async by wrapping it in Task.Run doesn't work the way you might think it does and it can introduce deadlocks. Furthermore you're event handler is now being called on a secondary thread and it may not be clear to whoever is managing this code that it actually isn't responding to the UI event directly. Can you please post the full set of code that is calling your async method and what, if anything, is using the event handler?

    It would also be useful to understand how you created the extension. Are you using the newer SDK with the async-enabled package stuff or are you updating an older extension? Have you run the analyzers that ship with the newer SDK to help detect issues like thread management? They are designed to help solve these kinds of issues.

    Also ensure that you're profiling your code. Is the delay happening getting to your handler or within your handler. If it is before your handler then it is likely something running before your extension gets called. Are you using the isolated environment when testing your extension such that other extensions won't get in the way?

    1 person found this answer helpful.
    0 comments No comments