ArgumentNullException thrown by Dispatcher.RunAsync

Hong 1,211 Reputation points
2023-09-05T15:45:42.29+00:00
if (dispatcher == null)
{
    //do nothing
}
else
{
    await dispatcher?.RunAsync(CoreDispatcherPriority.Normal, async () =>
    {

        try
        {
          ...
        }
        catch (Exception ex)
        {
        }
    });
}


The above code occasionally throws the following exception:

System.ArgumentNullException: Value cannot be null.
Parameter name: source
 Stack Trace:
   at System.WindowsRuntimeSystemExtensions.AsTask(IAsyncAction, CancellationToken) + 0x47

It is actually fairly frequent. I cannot reproduce it. It is reported by app analytics. Could anyone shed some light on this?

Universal Windows Platform (UWP)
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.