0
votes

I want to show toast notification from my app with the code not from push notifications.

Like My app was running and I opened the call task and after 5 secs I want to show toast notification on that call screen As My app is running on background and its obscured state.

Here is My Code and I am using Coding4fun toolkit:

private void RunBackgroundWorker()
        {
            PhoneCallTask callTask = new PhoneCallTask();
            callTask.PhoneNumber = "03336329631";
            callTask.DisplayName = "Arslan";
            callTask.Show();

            BackgroundWorker backroungWorker = new BackgroundWorker();

            backroungWorker.DoWork += ((s, args) =>
            {
                Thread.Sleep(5000);
            });

            backroungWorker.RunWorkerCompleted += ((s, args) =>
            {
                this.Dispatcher.BeginInvoke(() =>
                {
                    var toast = new ToastPrompt
                    {
                        Title = "Simple usage",
                        Message = "Message",
                        ImageSource = new BitmapImage(new Uri("..\\ApplicationIcon.png", UriKind.RelativeOrAbsolute))
                    };
                    toast.Show();
                }
            );
            });
            backroungWorker.RunWorkerAsync();
        }
1

1 Answers

2
votes

You can't run "workers" like this when your app is in suspended state.

You can however, run Background Agents - e.g. periodic agents - http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202942

You also can't show a ToastPrompt using Coding4Fun's library from a Background Agent - but you can use the ShellToast API - see "Toast Notifications for Background Agents" - http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh487170