Reputation: 1959
I'm creating my first application for my Windows Phone using the camera. And at shutdown I want to call a dispose-method to release resources from a MediaCapture object
. But I cannot find an event which triggers when the application shuts down.
Does anyone know how I can dispose this object at shutdown? Cause when closing the application now makes my phone freeze.
Upvotes: 0
Views: 712
Reputation: 721
In your app.xaml.cs you normally got this class
public sealed partial class App : Application
Inside you got two interresting methods already there when you create the project
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
// some code here
// will run when app launch
}
And this one
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
// some code here
}
So as you can read in the summary that explains the function, it is called when user suspend the application, but you don't know if the application will terminate or be resumed later, and I think you don't have a way to differentiate.
So I would suggest dispose your ressources inside the OnSuspending function
That is for Windows Phone 8.1 and Windows 8.1 metro style application
If you want to do that in a WPF project, you actually got an
OnExit(ExitEventArgs e)
see Msdn documentation here (for WPF only)
Msdn OnExit documentation page
Upvotes: 2