Tutorial :Does this Asynchronous Lambda Cryptica Code do what I think?


    Action<SPItemEventProperties> deleteAction = DeleteWorkspace;      AsyncCallback deleteDone = deleteAction.EndInvoke;      SPSecurity.RunWithElevatedPrivileges(() => deleteAction.BeginInvoke(properties, deleteDone, null));  

So this is suppose to call DeleteWorkspace Asynchronously and then call EndInvoke when its done, I wrote it but I am not positive it will work properly. I stepped through and it appears to work but the syntax is making me second guess myself cause I have never seen it done like this on the net...



It should work, but to really understand it let's pretend it were 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 code above, it looks like the 'Done' callback will go out of scope right away. However, the compiler will capture (close over) it with a closure, so that it's available when needed.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »