Passing OperationContext to an async call
C#, 3.5 - This is al开发者_运维技巧l back-end; there is no UI involved at all. I'm trying to call a function from another function asynchronously using BeginInvoke and EndInvoke. I need to call the method 4 times with different parameters and then, after all the calls are completed, I merge all the results and continue. It all works fine, except that the calls require the OperationContext for credentials and such. Is there an easy way to pass the OperationContext to the BeginInvoke statement somehow?
The BeginInvoke
statement is based on the type of the delegate
. If you require the OperationContext
, make it a parameter for the method, and you can then pass it into the function when calling BeginInvoke
.
You could try using OperationContextScope
from within a wrapper around your delegate.
精彩评论