How to make DataObjectSelector SelectObjects method asynchronous?

Soumabha Sarkar 41 Reputation points
2022-09-05T14:23:34.833+00:00

In our VS Extension, we have few Custom Object Selector which inherits from Microsoft.VisualStudio.Data.Framework.DataObjectSelector and we are overriding the SelectObjects abstract method. Inside overridden SelectObjects method, we are calling a time consuming method RetrieveObject() to get the data and returning a DataReader. And showing the data in VS Server Explorer hierarchy.

Because RetrieveObject() is a time consuming operation, the UI thread is blocked and we are getting UI Delay warning from VS. Also, SelectObjects is not async method, so we are not able to make the RetrieveObject() method async and await it inside SelectObjects method.

Is there any way to invoke RetrieveObject from SelectObjects without blocking the UI thread?

internal class MyProviderObjectSelector : Microsoft.VisualStudio.Data.Framework.DataObjectSelector  
{  
	protected override IVsDataReader SelectObjects(string typeName, object[] restrictions, string[] properties, object[] parameters)  
	{  
	  base.Site.Lock();  
	  try  
	  {  
		ObjectDataTable = null;  
		QueryResult = null;  
		MyProviderViewDataReader viewDataReader = null;  
		RetrieveObjects(typeName, restrictions, properties, parameters, out viewDataReader); // Want to make RetrieveObjects method Async and Await for the result so that UI is not blocked   
		if (null == QueryResult)  
		{  
		  // Mapping Code  
		  return new AdoDotNetTableReader(ObjectDataTable);  
		}  
		else  
		{	  
			if (viewDataReader != null)  
				return viewDataReader;  
			else  
				return GetViewDataReader();  
		}  
	  }  
	  finally  
	  {  
		base.Site.Unlock();  
	  }  
	}  
  
	// Other methods   
}
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,960 questions
{count} votes