using System.Globalization; using System.Threading; using System.Threading.Tasks; namespace Xylem.Common.Utils.TaskExec { /// /// Task execution uses an initialization-, an execution-, an event- /// and a finalization-routine. /// public class TaskExec { /// /// Definition of thread call back function /// public delegate void ThreadCallbackFunction(); /// /// A new task calling the init-, the cyclic execution and the final-function. /// The task adjusts the current culture. /// /// /// /// /// /// /// - Initial. /// public void NewTask(ThreadCallbackFunction initFn, ThreadCallbackFunction execFn, ThreadCallbackFunction finalFn, CultureInfo cultureInfo) { Thread.CurrentThread.CurrentUICulture = cultureInfo; Thread.CurrentThread.CurrentCulture = cultureInfo; initFn?.Invoke(); Task.Factory.StartNew(() => { Thread.CurrentThread.CurrentUICulture = cultureInfo; Thread.CurrentThread.CurrentCulture = cultureInfo; execFn?.Invoke(); Thread.Sleep(1000); }).ContinueWith(delegate { finalFn?.Invoke(); }); } } }