我有一个UWP应用程序,它在一个回调中请求扩展执行,该回调在下面的操作开始后被触发:
private async void HandleOnSyncStart(ISyncStart msg)
{
// request extended execution
ExtendedExecutionResult result = await
Utils.ExtendedExecutionHelper.RequestExtendedExecutionSessionAsync();
}
,但我收到以下错误
The group or resource is not in the correct state to perform the
requested operation. (Exception from HRESULT: 0x8007139F)
在下面显示的 RequestExtendedExecutionSessionAsync()方法的返回调用中抛出错误。这是堆栈跟踪:
at Windows.ApplicationModel.ExtendedExecution.ExtendedExecutionSession..ctor()
at MyProject.UWP.Utils.ExtendedExecutionHelper.<RequestExtendedExecutionSessionAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MyProject.UWP.MainPage.<HandleOnSyncStart>d__65.MoveNext()
在ExtendedExecutionHelper静态类的RequestExtendedExecutionAsync()方法中请求扩展执行会话,如下所示:
public static async Task<ExtendedExecutionResult> RequestExtendedExecutionSessionAsync()
{
ClearExtendedExecutionSession(); //first clear if any session granted
var newSession = new ExtendedExecutionSession();
newSession.Reason = ExtendedExecutionReason.Unspecified;
newSession.Description = "Extended Execution Request";
newSession.Revoked += OnExtendedExecutionSessionRevoked;
ExtendedExecutionResult result = await newSession.RequestExtensionAsync();
switch (result)
{
case ExtendedExecutionResult.Allowed:
Debug.WriteLine(string.Format("ExtendedExecutionHelper: ExtendedExecution allowed."));
session = newSession;
break;
case ExtendedExecutionResult.Denied:
Debug.WriteLine(string.Format("ExtendedExecutionHelper: ExtendedExecution denied."));
newSession.Dispose();
break;
}
return result; //ERROR
}
答案 0 :(得分:2)
在ExtendedExecutionSession
类的构造函数中抛出此异常。
堆栈跟踪: 在Windows.ApplicationModel.ExtendedExecution.ExtendedExecutionSession..ctor()
此异常可能由
引起任何时候都只能请求一个ExtendedExecutionSession;当一个当前处于活动状态时尝试创建另一个会话将导致从ExtendedExecutionSession构造函数抛出异常。
所以看起来ClearExtendedExecutionSession
无法处理以前运行的会话。如果您的代码是从this page采用的......也许代码有一些微妙的错误,如该页面上的一些评论所示。
您可以展示如何处理之前的运行会话。