Action<SPItemEventProperties> deleteAction = DeleteWorkspace;
AsyncCallback deleteDone = deleteAction.EndInvoke;
SPSecurity.RunWithElevatedPrivileges(() => deleteAction.BeginInvoke(properties, deleteDone, null));
所以这假设是异步调用DeleteWorkspace然后在完成后调用EndInvoke,我写了但是我不肯定它会正常工作。我走了进去似乎工作,但语法让我第二次猜测自己,因为我从来没有在网上看到它这样做...
评论
答案 0 :(得分:1)
它应该有用,但要真正理解它,让我们假装它是这样写的:
void RunAsync<T>(Action<T> action)
{
AsyncCallback Done = action.EndInvoke;
SPSecurity.RunWithElevatedPrivileges(() => action.BeginInvoke(properties, Done, null));
}
RunAsync(DeleteWorkspace);
请注意,在上面的代码中,看起来“完成”回调会立即超出范围。但是,编译器将使用闭包捕获(关闭)它,以便在需要时可用。