Esempio n. 1
0
        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("");
        }