async Task<string> LongProcessAsync(User user, int id, int count) { return await Task.Run<string>(() => { var result = LongProcess(user, id, count); this.DispatchLog(result); return result; }); }
string LongProcess(User user, int id, int count) { var seconds = 1000; var builder = new StringBuilder(5); builder.AppendFormat("[({0:hh.mm.ss}) Start - ThreadId: {1:000}, User: {2,-5}, Id: {3:000}", DateTime.Now, Thread.CurrentThread.ManagedThreadId, user.Name, id); Debug.WriteLine(builder.ToString()); Thread.Sleep(seconds * count); builder.AppendFormat(" - Waited {0,2}s", count); builder.AppendFormat(" - Stop ({0:hh.mm.ss})]", DateTime.Now); Debug.WriteLine(builder.ToString()); return builder.ToString(); }