Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 51 additions & 13 deletions src/Files.App/Extensions/DispatcherQueueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Func<T
return SafetyExtensions.IgnoreExceptions(() =>
{
if (dispatcher is not null)
return dispatcher.EnqueueAsync(function, priority);
else
return function();
{
try
{
return dispatcher.EnqueueAsync(function, priority);
}
catch (InvalidOperationException ex)
{
if (ex.Message is not "Failed to enqueue the operation")
throw;
}
}

return function();
}, App.Logger, typeof(COMException));
}

Expand All @@ -24,9 +34,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Func<T
return SafetyExtensions.IgnoreExceptions(() =>
{
if (dispatcher is not null)
return dispatcher.EnqueueAsync(function, priority);
else
return function();
{
try
{
return dispatcher.EnqueueAsync(function, priority);
}
catch (InvalidOperationException ex)
{
if (ex.Message is not "Failed to enqueue the operation")
throw;
}
}

return function();
}, App.Logger, typeof(COMException));
}

Expand All @@ -35,12 +55,20 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Action
return SafetyExtensions.IgnoreExceptions(() =>
{
if (dispatcher is not null)
return dispatcher.EnqueueAsync(function, priority);
else
{
function();
return Task.CompletedTask;
try
{
return dispatcher.EnqueueAsync(function, priority);
}
catch (InvalidOperationException ex)
{
if (ex.Message is not "Failed to enqueue the operation")
throw;
}
}

function();
return Task.CompletedTask;
}, App.Logger, typeof(COMException));
}

Expand All @@ -49,9 +77,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Action
return SafetyExtensions.IgnoreExceptions(() =>
{
if (dispatcher is not null)
return dispatcher.EnqueueAsync(function, priority);
else
return Task.FromResult(function());
{
try
{
return dispatcher.EnqueueAsync(function, priority);
}
catch (InvalidOperationException ex)
{
if (ex.Message is not "Failed to enqueue the operation")
throw;
}
}

return Task.FromResult(function());
}, App.Logger, typeof(COMException));
}

Expand Down