Is it possible to use TPL Task<TResult> to asynchronously call a thread-safe method with the following signature and get a logical return value and output parameter?
public bool TryGet(T1 criteria, out T2 output)
Obviously, I cannot use a lambda expression because of the output parameter. In addition, I cannot solve the problem by defining a user delegate, such as below, and passing it to the Task<TResult> constructor, since I need to pass the criteria as a strongly typed parameter that the constructor does not support.
public delegate TResult Func<T1, T2, TResult>(T1 arg1, out T2 arg2);
Is it best to write a shell like below and invoke 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); }
It just seems a little inelegant and a little thoughtful.
source share