/// <summary> Executes the main thread operation. Void </summary> /// /// <remarks> Fess59, 26.01.2018. </remarks> /// /// <param name="action"> The action. </param> /// <param name="continueExceptionMethod"> (Optional) The continue exception method. Выполнится /// при ошибке в method. </param> /// <param name="continueMethod"> (Optional) The continue method. Выполнится после /// method и continueExceptionMethod. </param> internal static void _ExecuteMainThread <TContext>(Action <TContext> action, Action <TContext, Exception> continueExceptionMethod = null, Action <TContext> continueMethod = null, bool isAsync = true) where TContext : DCTContext, new() { var name = GetCategoryName(); DispatcherHelper.Execute(() => execute(name, action, continueExceptionMethod: continueExceptionMethod, continueMethod: continueMethod), isAsync: isAsync, name: name); }
/// <summary> Executes the main thread operation. With result async </summary> /// /// <remarks> Fess59, 26.01.2018. </remarks> /// /// <param name="action"> The action. </param> /// <param name="continueExceptionMethod"> (Optional) The continue exception method. Выполнится /// при ошибке в method. </param> /// <param name="continueMethod"> (Optional) The continue method. Выполнится после /// method и continueExceptionMethod. </param> /// <param name="complete"> The complete. Для отправки результата в другой блок /// кода, используется в ExecuteAsync </param> internal static void _ExecuteMainThread <TContext, TResult>(Func <TContext, TResult> action, Action <TContext, TResult> complete, Action <TContext, Exception> continueExceptionMethod = null, Action <TContext> continueMethod = null) where TContext : DCTContext, new() { var name = GetCategoryName(); DispatcherHelper.Execute(() => execute(name, action, continueExceptionMethod: continueExceptionMethod, continueMethod: continueMethod, complete: (data, result) => _ExecuteAsync <TContext>(dataAsync => complete.Invoke(dataAsync, result)))); }
public void Write(LogEntryType entryType, string format, params object[] args) { var text = string.Format(format, args); // handle thread safety here, otherwise it would have been handled everywhere where calling the write method DispatcherHelper.Execute(() => Entries.Add(new LogEntry(entryType, text))); }
public void SendStreamText(string text) { var callback = ReceiveStreamText; if (callback != null) { DispatcherHelper.Execute(() => callback(text)); } }
void loop() { while (true) { if (cancellationTokenSource.Token.IsCancellationRequested) { DispatcherHelper.Execute(() => { State = InputStreamState.Stopped; CommandManager.InvalidateRequerySuggested(); }); return; } streamService.SendStreamText(randomText.GetRandomString()); Thread.Sleep(2500); } }
/// <summary> /// Асинхронное выполенение метода, без заморочек просто Task /// </summary> /// <param name="action"></param> public static void ExecuteCurrentDispatcher(Action <BulletinContext> action, Action <BulletinContext, Exception> continueExceptionMethod = null, Action <BulletinContext> continueMethod = null, string name = "") { DispatcherHelper.Execute(() => Execute(action, continueExceptionMethod: continueExceptionMethod, continueMethod: continueMethod), false); }