Open
Description
Describe the bug
Hi there I have a background task that will read .NET Channels message and generate ToastContentBuilder() based on that.
However, I notice some random occurrence of System.AccessViolationException after several .Show() is called. It tends to happen on the 3rd call to the .Show() command if that helps with some clues.
Here is my example code.
while (await _progressMqSvc.WaitForMessageAsync(cancellationToken))
{
if (_progressMqSvc.TryGetMessage(out var progressMsg) && progressMsg is not null)
{
try
{
var title = progressMsg.Title;
var description = progressMsg.Description;
new ToastContentBuilder()
.AddArgument("conversationId", 9813)
.AddText($"{title}")
.AddText($"{description}")
.Show();
}
catch (AccessViolationException e)
{
await _logger.Log(new LogMessage("Unable to raise a toast notification", LogLevel.Error,
exception: e));
}
await _logger.Log(new LogMessage($"{progressMsg.Title} (TaskID #{progressMsg.TaskId}):{progressMsg.Description}"));
}
}
at ABI.Windows.UI.Notifications.IToastNotifierMethods.Show(WinRT.IObjectReference, Windows.UI.Notifications.ToastNotification)
at CommunityToolkit.WinUI.Notifications.ToastContentBuilder.Show(CommunityToolkit.WinUI.Notifications.CustomizeToast)
at PASApp.DataBroker.TestConsoleApp.ToasterNotificationProgressChannelReaderConsumer+<ExecuteAsync>d__3.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionContextCallback(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext(System.Threading.Thread)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter+<>c.<OutputWaitEtwEvents>b__12_0(System.Action, System.Threading.Tasks.Task)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+ContinuationWrapper.Invoke()
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action, Boolean)
at System.Threading.Tasks.Task.RunContinuations(System.Object)
at System.Threading.Tasks.Task.FinishContinuations()
Expected behavior
Toaster notification should keep showing as there are notificaitons to be pushed out
Screenshot
Target OS Version
Windows 10.0.22621.0
Visual Studio Version
2022
Activity