Problem Statement:
I have a Form A and here i am calling one API and it is taking few seconds to complete its operation. So, in this duration the user is closing the Form A. Due to this the object created in Form A gets disposed.
When the response comes back from API and try to call DataBinding() method it throws this exception: System.InvalidOperationException: 'Databinding cannot occur unless a BindingContext or BindingContext Control has been specified.'
Code:
public partial class FormA{
private async void BindData(){
var response = await _service.APICall(id);
ultraComboEditor.DataSource = response;
ultraComboEditor.DataBind(); //This throws the exception.
}
}
Question:
How to avoid this exception?
I can add a try catch block and avoid this exception, but it is not a good approach. So, is there any better solution to this?