Is it possible to use a TPL Task<TResult>
to asynchronously invoke a thread-safe method with the following signature and retrieve the boolean return value and the output parameter?
public bool TryGet(T1 criteria,
out T2 output)
Obviously I can't use a lambda expression because of the output parameter. Additionally, I cannot solve the problem by defining a custom delegate such as below and passing that to the Task<TResult>
constructor as I need to pass the criteria as a strongly typed parameter which the constructor does not support.
public delegate TResult Func<T1, T2, TResult>(T1 arg1,
out T2 arg2);
Is the best option to write a wrapper such as below and invoke that asynchronously instead?
public Tuple<bool, T2> TryGetWrapper(T1 criteria)
{
T2 output;
bool result = obj.TryGet(criteria,
out output);
return new Tuple<bool, T2>(result,
output);
}
Just seems a bit inelegant and has a bit of a whiff about it.