Silverlight – iDLEDEtectionMode Error Windows Phone 7

I have a checkbox. In its check event I want to turn off IdleDetectionMode and unchecked event I want to turn on. This is the code: –

private void chkRunInBackground_Checked(object sender, RoutedEventArgs e)
{
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;

}

private void chkRunInBackground_Unchecked(object sender, RoutedEventArgs e)
{
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Enabled;

}

Already The checked events are running normally, but in the unacquired events, the IdleDetection mode cannot be started after being disabled. Why do I need to apply this restriction, and what can I do to resolve it?

From MSDN:

In the current release, application
idle detection cannot be enabled in a
single application instance once it
has been disabled. Doing so throws an
exception. In future releases this may< br> be supported, so your application may
choose to disable application idle
detection when it is no longer needed
and catch the expected exception.

The following code snippet This implementation is shown.

// Custom function to turn off idle detection. This will throw an exception in the current release.
public void TryReenableApplicationIdleDetection()
{
bool didEnable = false;
try
{
Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode =
Microsoft.Phone.Shell.IdleDetectionMode. Enabled;
didEnable = true;
}
catch (InvalidOperationExcepti on ex)
{
// This exception is expected in the current release.
}

// possibly use the value of didEnable to decide what to do next
// if it is'true' then your app will be deactivated
// if it is'false' then your app will keep running
}

< /p>

I have a checkbox. In its check event I want to turn off IdleDetectionMode and unchecked event I want to turn on. This is the code: –

private void chkRunInBackground_Checked(object sender, RoutedEventArgs e)
{
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;

}

private void chkRunInBackground_Unchecked(object sender, RoutedEventArgs e)
{
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Enabled;

}

The checked event is running normally , But in unacquired events, IdleDetection mode cannot be started after being disabled. Why should this restriction be applied and what should I do to resolve it?

From MSDN:

In the current release, application
idle detection cannot be enabled in a
single application instance once it
has been disabled. Doing so throws an
exception. In future releases this may
be supported, so your application may
choose to disable application idle
detection when it is no longer needed
and catch the expected exception.

The following code snippet shows this implementation.

// Custom function to turn off idle detection. This will throw an exception in the current release.
public void TryReenableApplicationIdleDetection()
{
bool didEnable = false;
try
{
Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode =
Microsoft.Phone.Shell.IdleDetectionMode.Enabled;
didEnable = true;
}
catch (InvalidOperationException ex)
{
// This exception is expecte d in the current release.
}

// possibly use the value of didEnable to decide what to do next
// if it is'true' then your app will be deactivated
// if it is'false' then your app will keep running
}

Leave a Comment

Your email address will not be published.