InvokeAsync mystery - exception while Show with the same window works fine
Posted: Thu Apr 06, 2023 4:08 pm
I've tried to solve the below issue, so far without success.
I created a WPF window with on it one of the fancy Busy Indicators (some moving object, like a circle) from the Syncfusion library. Just before filling a DataGrid I open the window (from a C project within the same solution) where this moving object is on. This worked, but it only started moving when the whole datagrid was filled - the moment I would close it...
After trying a couple of Async changes without success, I asked Syncfusion support and they sent me a project using more or less my methods, also filling a datagrid -- and the object remained responsive from the start.
I implemented the code in my program which only differed in the way namespaces and classes were organized. And that directly gave a problem. See the code below, brought back to a minimum.
1 When I call window.Show the window appears without a problem (but nothing moves in it)
2 When I replaced it with the Syncfusion suggested await Application.Current.Dispatcher.InvokeAsync(() => window.Show()); I get an exception:
$exception {"Object reference not set to an instance of an object."} System.NullReferenceException
StackTrace " at IC2CSMethods.iConnectC.<ShowBusyWindow>d__13.MoveNext()
I really have no idea why this exception occurs in that InvoceAsync line while window.Show works fine, or what d__13.MoveNext() is supposed to be.
So I also don't know how to solve it. I tried reorganizing a few things in used namespace/class as this seems the only difference with the working (and moving) Syncfusion sample but without succes.
Does anybody have an idea what causes this and how to prevent that?
Dick
I created a WPF window with on it one of the fancy Busy Indicators (some moving object, like a circle) from the Syncfusion library. Just before filling a DataGrid I open the window (from a C project within the same solution) where this moving object is on. This worked, but it only started moving when the whole datagrid was filled - the moment I would close it...
After trying a couple of Async changes without success, I asked Syncfusion support and they sent me a project using more or less my methods, also filling a datagrid -- and the object remained responsive from the start.
I implemented the code in my program which only differed in the way namespaces and classes were organized. And that directly gave a problem. See the code below, brought back to a minimum.
1 When I call window.Show the window appears without a problem (but nothing moves in it)
2 When I replaced it with the Syncfusion suggested await Application.Current.Dispatcher.InvokeAsync(() => window.Show()); I get an exception:
$exception {"Object reference not set to an instance of an object."} System.NullReferenceException
StackTrace " at IC2CSMethods.iConnectC.<ShowBusyWindow>d__13.MoveNext()
I really have no idea why this exception occurs in that InvoceAsync line while window.Show works fine, or what d__13.MoveNext() is supposed to be.
So I also don't know how to solve it. I tried reorganizing a few things in used namespace/class as this seems the only difference with the working (and moving) Syncfusion sample but without succes.
Does anybody have an idea what causes this and how to prevent that?
Code: Select all
public async System.Threading.Tasks.Task ShowBusyWindow()
//#s Show SyncFusion Busyindicator in small WPF window 4-4-2023
{
var window = new SFTools.BusyWindow();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
// Show the busy indicator on the UI thread
await Application.Current.Dispatcher.InvokeAsync(() => window.Show()); // Nothing shows because of Object not set error
// window.Show(); / / This shows the window fine
}