我的应用程序上有一个后台代理,在我发送Toast通知之前运行良好,它会抛出一个未处理的异常,异常对象消息为:“对象引用未设置为对象的实例。” OnInvoke方法与我完全正常工作的异步请求是异步的。 抛出异常的代码是以下
ShellToast toast = new ShellToast();
toast.Title = "hello";
toast.Show();
我不知道问题出在哪里,提前感谢您的帮助。
修改 这是Stacktrace:
at Microsoft.Phone.Shell.ShellToast.Show()
at ScheduledTaskAgent1.ScheduledAgent.<OnInvoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore. <ThrowAsync>b__4(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
答案 0 :(得分:0)
您可以使用另一个简单的吐司,只需转到NuGet包,搜索 Toastinet 并安装或从here下载。
下载后,将其名称空间添加到.xaml文件中,如下所示
xmlns:toastinet="clr-namespace:Toastinet;assembly=Toastinet"
并且toast的声明如下
<toastinet:Toastinet Grid.ColumnSpan="2" x:Name="myToast"
Duration="1"
Height="50"
FontSize="20"
Margin="0,10,0,0"
ShowLogo="False"
AnimationType="Vertical"
Background="#FFFFFF "
Foreground="#4e0916"
TextWrapping="Wrap"
Canvas.ZIndex="1"
VerticalAlignment="Top" />
并在.cs中的任何地方使用此吐司。如下
this.myToast.Message="hello";