async Task <string> AsyncTaskGet(CancellationToken cancellationToken, string url) { _ping.iswork = true; string result = ""; //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& task1 = Task.Run(() => { var tcs = new TaskCompletionSource <string>(); _ping.result = ""; try { result = _ping.GETnoas(cancellationToken, url); tcs.SetResult("ok"); } catch (OperationCanceledException e) { tcs.SetException(e); } catch (Exception e) { tcs.SetException(e); } return(tcs.Task); }); //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& try { await task1; _ping.iswork = false; if (Task_Completed != null) { Task_Completed(result); } Wait.Close(); task1.Dispose(); task1 = null; } catch (Exception e) { _ping.stop(); _ping.exit(""); dialog.Show("ОШИБКА pingPrepare " + e.Message.ToString()); _ping.stop();//без ошибки должна выполниться шататно } return(""); }
public static void analiz_closing_thread(PING p, PING_prepare prep) { if (p != null) { p.stop(); } if (prep != null) { prep.stop(); byte ct = 0; while (!prep.stateTASKisCanceled()) { ct++; if (ct == 5) { Wait.Create("Ждите идет прерывание пинга", false); LongtaskPingCANCELING.enable(p, prep); break; } Thread.Sleep(100); } } stop(); }