diff --git a/sources/MVCFramework.AsyncTask.pas b/sources/MVCFramework.AsyncTask.pas index f161ebf7..67c7ce1f 100644 --- a/sources/MVCFramework.AsyncTask.pas +++ b/sources/MVCFramework.AsyncTask.pas @@ -34,6 +34,7 @@ type TMVCAsyncBackgroundTask = reference to function: T; TMVCAsyncSuccessCallback = reference to procedure(const BackgroundTaskResult: T); TMVCAsyncErrorCallback = reference to procedure(const Expt: Exception); + TMVCAsyncAlwaysCallback = reference to procedure; TMVCAsyncDefaultErrorCallback = reference to procedure(const Expt: Exception; const ExptAddress: Pointer); @@ -42,7 +43,8 @@ type class function Run( Task: TMVCAsyncBackgroundTask; Success: TMVCAsyncSuccessCallback; - Error: TMVCAsyncErrorCallback = nil): ITask; + Error: TMVCAsyncErrorCallback = nil; + Always: TMVCAsyncAlwaysCallback = nil): ITask; end; var @@ -66,7 +68,8 @@ uses class function MVCAsync.Run( Task: TMVCAsyncBackgroundTask; Success: TMVCAsyncSuccessCallback; - Error: TMVCAsyncErrorCallback): ITask; + Error: TMVCAsyncErrorCallback; + Always: TMVCAsyncAlwaysCallback): ITask; var LRes: T; begin @@ -98,14 +101,26 @@ begin LCurrException := Exception(Ex); try if Assigned(Error) then - Error(LCurrException) + begin + Error(LCurrException); + end else + begin gDefaultTaskErrorHandler(LCurrException, ExceptionAddress); + end; finally FreeAndNil(LCurrException); end; end); end; + if Assigned(Always) then + begin + TThread.Queue(nil, + procedure + begin + Always(); + end); + end; end); end;