I have a custom PropertyGrid editor that launches a form and allows the user to make some selections. These selections are used to provide the property value. The form makes a call to a web service to retrieve data for the user to choose from. Currently, this web service call is done synchronously. From what I understand, such calls should ideally be made asynchronously, so as not to freeze the application.
Is there a way that I could do this asynchronously?
It seems like I would need to make my EditValue method async, but the class that I am over-riding (UITypeEditor) does not appear to have this option.
This answer provides a nice background for how I have my custom PropertyGrid editor implemented. However, I will also provide a very basic code snippet to provide a rough idea of what I am trying to do. I'm not using a form in this example, but the important thing to understand is that I am trying to await an async call within my EditValue method.
class FooEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
using (var client = MasterContainer.Resolve<ValueWebClient>())
{
var value = await client.GetCurrentValue(); // visual studio shows await can only be used in async method error
return value;
}
}
}
I suppose one approach might be to load all of your data up-front so that you don't have to make the call. However, the data could be changed while the user is working, so I would prefer not to take that approach.