There is a code snippet:
Dataflow :
var ActionBlock = TransformBlock<ActionParams, string>(async n => try { Task.Run(n.func); } catch (Exception e) { if (MessageBoxResult.Yes == ExceptionMessageBase(e.Message, a)) { //бла бл } } )}; What is sent to him:
public static void Auth() { Api ap = new Api(); AuthPool.Add(() => { ap.Authorize(_aap); }, new ActionParams()); } Add:
public void Add(Action func, PMData data, string name = null) { ActionParams _pack = new ActionParams(); _pack.TargetAction = func; _pack.ActionName = name; _pack.Data = data; ActionBlock.Post(_pack); } But the exception handling arising n.func does not work. More precisely, the exception call inside the function is triggered and the program crashes.
If n.func run without a Task then the exception is caught perfectly. But how to catch exceptions arising in the thread where the function is executed and process it in external code?