次の方法で共有


Silverlight debugging tip

I'm building a Deep Zoom application and have been frustrated when it often has some stupid bug (my own of course) and the whole app just disappears. Eventually I realized a quick and dirty snippet I plan to drop into every future Silverlight app. Its not a replacement for the debugger, but its great when you hit an unanticipated snarl and dont have the debugger attached.

 In the application file (typically App.xaml.cs) just hook the unhandled exception handler into the browsers alert function.

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
System.Windows.Browser.HtmlPage.Window.Alert(e.ExceptionObject.ToString());
}

A very simple change, but anything you dont anticipate gets popped up in the browser. Of course, you might want to wrap it in a "#if DEBUG" statement to prevent accidentally shipping the final version that way!

Comments

  • Anonymous
    April 11, 2008
    Very helpful tip Ben, thank you!