Is this asynchronous lambda cryptography code what I think it is?
Action<SPItemEventProperties> deleteAction = DeleteWorkspace;
AsyncCallback deleteDone = deleteAction.EndInvoke;
SPSecurity.RunWithElevatedPrivileges(() => deleteAction.BeginInvoke(properties, deleteDone, null));
So, suppose you call DeleteWorkspace asynchronously and then call EndInvoke when done, I wrote it, but I'm not sure if it will work correctly. I went through and it seems to work, but the syntax makes me a second guess because I've never seen it done this way on the net ...
Comments?
0
a source to share
1 answer
This should work, but in order to figure it out, let's pretend it's written like this:
void RunAsync<T>(Action<T> action)
{
AsyncCallback Done = action.EndInvoke;
SPSecurity.RunWithElevatedPrivileges(() => action.BeginInvoke(properties, Done, null));
}
RunAsync(DeleteWorkspace);
Note that in the above code, it looks like the Finish callback will disappear right away. However, the compiler will capture (close) it by closing it so that it is available when needed.
+1
a source to share