My WP8 app displays a message in the system tray for a few seconds when navigated to. But the following method I use to display the message always throws an System.NullReferenceException: Object reference not set to an instance of an object. I'm baffled to why this is, maybe someone can point out maybe whats wrong? The code is:
private void runSystrayMessage(bool isVisible, string text, int length)
{
try
{
SystemTray.ProgressIndicator.IsVisible = true;
SystemTray.ProgressIndicator.IsIndeterminate = isVisible;
SystemTray.ProgressIndicator.Text = text;
}
catch (Exception e)
{
Debug.WriteLine("Exception caught" + e);
}
DispatcherTimer timer = new DispatcherTimer();
try
{
timer.Interval = TimeSpan.FromMilliseconds(length);
}
catch(ArgumentOutOfRangeException e)
{
Debug.WriteLine("ArgumentOutOfrangeException caught" + e);
}
timer.Tick += (sender, args) =>
{
try
{
SystemTray.ProgressIndicator.IsVisible = false;
}
catch(System.InvalidOperationException e)
{
Debug.WriteLine("InvalidOperationException caught" + e);
}
timer.Stop();
};
timer.Start();
}
The full Exception message is:
System.NullReferenceException: Object reference not set to an instance of an object.
at ContosoSocial.StartPage.<>c__DisplayClass1.b__0(Object sender, EventArgs args)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)