I hit the following issue bouncing around an app that utilised the SmsComposeTask today. I have simplified the code to the following for demonstration purposes:
private void OnAdClick(object sender, MouseButtonEventArgs e)
{
SmsComposeTask sms = new SmsComposeTask();
sms.To = "111";
sms.Body = "blah"; �
sms.Show();
}
Issue:
When clicking the button that creates the SMS compose task in quick succession the following occurs.
InvalidOperationException
Navigation is not allowed when the task is not in the foreground. Error: -2147220989
at Microsoft.Phone.Shell.Interop.ShellPageManagerNativeMethods.CheckHResult(Int32 hr)
at Microsoft.Phone.Shell.Interop.ShellPageManager.NavigateToExternalPage(String pageUri, Byte[] args)
at Microsoft.Phone.Tasks.ChooserHelper.Navigate(Uri appUri, ParameterPropertyBag ppb)
at Microsoft.Phone.Tasks.SmsComposeTask.Show()
at Demo.OnAdClick(Object sender, MouseButtonEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
at Microsoft.Xna.Framework.Input.UnsafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Microsoft.Xna.Framework.Input.SafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Microsoft.Xna.Framework.Input.WindowMessageHooker.Hook.WndProc(IntPtr msgWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
Cause:
The cause is that the first click will launch the SmsComposeTask causing the application to be deactivated i.e sent to the background, with the second click being handled after the deactivated event has occured so its just a matter of cleaning up your click handler.
Kind Regards,
Nick Harris
35ºC, 95ºF bedroom is like a sauna today, difficult to concerntrate, bring on autumn:)