当前位置: 首页>>代码示例>>C#>>正文


C# Task.GetAwaiter方法代码示例

本文整理汇总了C#中System.Threading.Tasks.Task.GetAwaiter方法的典型用法代码示例。如果您正苦于以下问题:C# Task.GetAwaiter方法的具体用法?C# Task.GetAwaiter怎么用?C# Task.GetAwaiter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Tasks.Task的用法示例。


在下文中一共展示了Task.GetAwaiter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeginVerify

 public void BeginVerify()
 {
     string connectionString = ConnectionInfoToConnectionString(_connectionInfo);
     _connection = new SqlConnection(connectionString);
     _task = _connection.OpenAsync();
     _task.GetAwaiter().OnCompleted(OnOpenComplete);
 }
开发者ID:yanivru,项目名称:Mabado,代码行数:7,代码来源:ConnectionStringVerifier.cs

示例2: Calculate

    public void Calculate()
    {
      if (m_calculating) return;

      m_calculating = true;

      var t = new Task(() =>
      {
        foreach (var v in Lines.Take(m_structure.Components.Count))
          v.Recalculate(false);

        recalculateTotal(false);

      });

      t.GetAwaiter().OnCompleted(() =>
      {
        foreach (var v in Lines.Take(m_structure.Components.Count))
          v.FireAllUpdated();

        CombinedLine.FireAllUpdated();

        m_calculating = false;

        OnCalculationFinished(EventArgs.Empty);
      });

      t.Start();
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:29,代码来源:BondStructureFwdAnalysis.cs

示例3: refreshData

    private void refreshData()
    {
      if (!m_args.IsOk())
        return;

      var task = new Task<IDictionary<BondMarket, IDictionary<BondMarket, CorrelationValue>>>(() =>
      {
        var firstDict = new Dictionary<BondMarket, IDictionary<BondMarket, CorrelationValue>>();

        Array.ForEach(LiveMarkets.Markets, x => firstDict.Add(x, new Dictionary<BondMarket, CorrelationValue>()));

        for(int i=0;i<LiveMarkets.Markets.Length;++i)
          for (int j = i + 1; j < LiveMarkets.Markets.Length; ++j)
          {
            var corr = CMTHelper.GetRollingCorrelation(LiveMarkets.Markets[i], m_args.Tenor, LiveMarkets.Markets[j],
              m_args.Tenor, Enums.Focus.Yield, m_args.WindowLength);

            firstDict[LiveMarkets.Markets[i]][LiveMarkets.Markets[j]]
              = firstDict[LiveMarkets.Markets[j]][LiveMarkets.Markets[i]]
                = new CorrelationValue(corr, m_args.WindowLength, m_args.DisplayMeasure, m_args.ColorMeasure);

          }

        return firstDict;
      });

      task.GetAwaiter().OnCompleted(() =>
      {
        m_dt.Rows.Clear();
        for(int i=0;i<LiveMarkets.Markets.Length;++i)
        {
          var marketI = LiveMarkets.Markets[i];
          var row = m_dt.NewRow();
          row[0] = EnumDescriptionAttribute.GetDescription(marketI);

          for(int j=0;j<LiveMarkets.Markets.Length;++j)
          {
            var marketJ = LiveMarkets.Markets[j];

            if (marketJ == marketI) continue;

            row[j+1] = task.Result[marketI][marketJ];
          }
          m_dt.Rows.Add(row);
        }

        btnGo.Enabled = true;
      });

      btnGo.Enabled = false;
      task.Start();
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:52,代码来源:CMTCorrelationCompare.cs

示例4: SpreadDefinition

    public SpreadDefinition(MonthYearOffset long_, MonthYearOffset short_, bool scheduleDataBuild_=true )
    {
      Long = long_;
      Short = short_;

      if (scheduleDataBuild_)
      {
        Task t = new Task(() => buildData());
        t.GetAwaiter().OnCompleted(() => m_hasBuiltData = true);
        t.Start();
      }
      else
        buildData();
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:14,代码来源:SpreadDefinition.cs

示例5: Exception

        public static Exception Exception(Task task)
        {
            Guard.ArgumentNotNull("task", task);

            try
            {
                task.GetAwaiter().GetResult();
                return null;
            }
            catch (Exception ex)
            {
                return ex;
            }
        }
开发者ID:JoB70,项目名称:xunit,代码行数:14,代码来源:Record.cs

示例6: LoadDataSourceAsync

        private async Task LoadDataSourceAsync()
        {
           
            var task = new Task<ReturnValue<DataTableSet>> (() => DataTableSet.FromConfigFile(DataSourceConfigPath));
            var dts = await task;
            if (dts.Success)
            {
                TableSet = dts.Value as DatabaseDataTableSet;
            }
            else
            {
                Log.Debug(dts.ToString());
            }

            var awaiter = task.GetAwaiter();


        }
开发者ID:ninerats,项目名称:DataTools,代码行数:18,代码来源:SearchMainForm.cs

示例7: MoveNext

            public void MoveNext()
            {
                int result;
                try
                {
#pragma warning disable 0219 // doFinallyBodies is never used
                    bool doFinallyBodies = true;
#pragma warning restore
                    if (state != 1)
                    {
                        if (state != -1)
                        {
                            task = Task<int>.Factory.StartNew(() => 5);
                            awaiter = task.GetAwaiter();
                            if (awaiter.IsCompleted)
                            {
                                goto Label_GetResult;
                            }
                            state = 1;
                            doFinallyBodies = false;
                            awaiter.OnCompleted(moveNextDelegate);
                        }
                        return;
                    }
                    state = 0;
                  Label_GetResult: // target of state=1
                    int awaitResult = awaiter.GetResult();
                    awaiter = default(TaskAwaiter<int>);
                    result = awaitResult;
                }
                catch (Exception e)
                {
                    state = -1;
                    builder.SetException(e);
                    return;
                }
                state = -1;
                builder.SetResult(result);
            }
开发者ID:Buildstarted,项目名称:eduasync,代码行数:39,代码来源:Program.cs

示例8: generate

    private void generate()
    {
      var args =
        new RecentMovesGenerationArgs
        {
          CMTCurvePoints = new[] { 3d, 5d, 7d, 10d, 13d, 15d, 18d, 20d, 25d, 30d },
          PeriodLenghts = new[] { 1, 5, 10, 21, 42, 63 }
        };

      var task =
        new Task<IList<Tuple<string, IList<Tuple<string, double>>>>>(
          () => RecentMovesHelper.GetGraphData(
            args));

      task.GetAwaiter().OnCompleted(() =>
      {
        var data = task.Result;
        columnChartMultiArea1.Create(
          rows_: args.Markets.Length,
          columns_: args.CMTCurvePoints.Length,
          data_: data,
          xAxisLabelFormatString_: null,
          yAxisLabelFormatString_: "##0.0#");

        columnChartMultiArea1.SetColumnColors(
          x => Singleton<SI.Controls.SpectrumColoursPositiveNegative>.Instance.GetColor(x, 3d));

        var maxValue = data.Aggregate(0d,
          (current, item) => item.Item2.Select(innerItem => Math.Abs(innerItem.Item2)).Concat(new[] {current}).Max());
        columnChartMultiArea1.StandardizeYAxisLimits(maxValue);

        LookFeel.ProcessControl(this);
      });

      task.Start();
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:36,代码来源:RecentMovesControl.cs

示例9: refreshData

        private void refreshData() {
            if (!OrchestradeCommon.Util.AccessHelper.HasAccess(ACCESS_NAME)) {
                GUIHelper.Display(this, "Access " + ACCESS_NAME + " denied for user " + OrchestradeUtils.CurrentUser());
                return;
            }

            var date = getSettleDate();
            if (date != null)
            {
                refreshButton.Enabled = false;
                settleDateEdit.Enabled = false;


                approvalsGrid.UseWaitCursor = true;
                shortSaleCapacityGrid.UseWaitCursor = true;

                Task<List<Approval>> task1;
                Task<BindingList<ISINAvailability>> task2;

                task1 = new Task<List<Approval>>(() => manager.GetShortSaleApprovalRequests(date));
                task2 = new Task<BindingList<ISINAvailability>>(() => new BindingList<ISINAvailability>(manager.GetISINAvailability(date)));

                task1.GetAwaiter().OnCompleted(() =>
                    {
                        approvalsGrid.BeginUpdate();
                        this.approvalsGrid.DataSource = task1.Result;
                        approvalsGrid.EndUpdate();
                        approvalsGrid.UseWaitCursor = false;
                        task2.Start();
                    });

                task2.GetAwaiter().OnCompleted(() =>
                    {
                        shortSaleCapacityGrid.BeginUpdate();
                        this.shortSaleCapacityGrid.DataSource = task2.Result;
                        shortSaleCapacityGrid.EndUpdate();
                        shortSaleCapacityGrid.UseWaitCursor = false;
                        refreshButton.Enabled = true;
                        settleDateEdit.Enabled = true;
                    });

                task1.Start();
            }
        }
开发者ID:heimanhon,项目名称:researchwork,代码行数:44,代码来源:LimitMonitoringPanel.cs

示例10: switch

            void IAsyncStateMachine.MoveNext()
            {
                try
                {
                    bool doFinallyBodies = true;
                    TaskAwaiter<int> localAwaiter;
                    int localLhs;

                    switch (state)
                    {
                        case -3:
                            goto Done;
                        case 0:
                            goto FirstAwaitContinuation;
                        case 1:
                            goto SecondAwaitContinuation;
                    }
                    // Default case - first call (state = -1)
                    y = 10;
                    z = Task.FromResult(10);
                    localAwaiter = z.GetAwaiter();
                    localLhs = y;
                    if (localAwaiter.IsCompleted)
                    {
                        goto FirstAwaitCompletion;
                    }
                    stack = localLhs;
                    state = 0;
                    awaiter = localAwaiter;
                    builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                    doFinallyBodies = false;
                    return;
                FirstAwaitContinuation:
                    localLhs = (int) stack;
                    stack = null;
                    localAwaiter = awaiter;
                    awaiter = default(TaskAwaiter<int>);
                    state = -1;
                FirstAwaitCompletion:
                    int localRhs = localAwaiter.GetResult();
                    x = localLhs * localRhs;

                    // Second section of code...
                    task = Task.FromResult(20);

                    string localArg0 = "{0} {1}";
                    int localArg1 = x;
                    localAwaiter = task.GetAwaiter();
                    if (localAwaiter.IsCompleted)
                    {
                        goto SecondAwaitCompletion;
                    }
                    var localTuple = new Tuple<string, int>(localArg0, localArg1);
                    stack = localTuple;
                    state = 1;
                    awaiter = localAwaiter;
                    builder.AwaitUnsafeOnCompleted(ref awaiter, ref this);
                    doFinallyBodies = false;
                    return;
                SecondAwaitContinuation:
                    localTuple = (Tuple<string, int>) stack;
                    localArg0 = localTuple.Item1;
                    localArg1 = localTuple.Item2;
                    stack = null;
                    localAwaiter = awaiter;
                    awaiter = default(TaskAwaiter<int>);
                    state = -1;
                SecondAwaitCompletion:
                    int localArg2 = localAwaiter.GetResult();
                    Console.WriteLine(localArg0, localArg1, localArg2);
                }
                catch (Exception ex)
                {
                    state = -2;
                    builder.SetException(ex);
                    return;
                }
            Done:
                state = -2;
                builder.SetResult();
            }
开发者ID:petemulholland,项目名称:learning,代码行数:81,代码来源:LogicalStackDecompiled.cs

示例11: OnAuthenticate

        private void OnAuthenticate(Task result, ClientState state)
        {
            SslStream sslStream = (SslStream)state.Stream;

            try
            {
                result.GetAwaiter().GetResult();
                _log.WriteLine("Server authenticated to client with encryption cipher: {0} {1}-bit strength",
                    sslStream.CipherAlgorithm, sslStream.CipherStrength);

                // Start listening for data from the client connection.
                sslStream.BeginRead(state.ReceiveBuffer, 0, state.ReceiveBuffer.Length, OnReceive, state);
            }
            catch (AuthenticationException authEx)
            {
                _log.WriteLine(
                    "Server disconnecting from client during authentication.  No shared SSL/TLS algorithm. ({0})",
                    authEx);
            }
            catch (Exception ex)
            {
                _log.WriteLine("Server disconnecting from client during authentication.  Exception: {0}",
                    ex.Message);
            }
            finally
            {
                state.Dispose();
            }
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:29,代码来源:DummyTcpServer.cs

示例12: reCalcClusterFlyZScores

    internal void reCalcClusterFlyZScores(int clusterSeriesIndex_, bool fireUpdate_=true)
    {
      var t = new Task(() =>
      {
        foreach (var line in Lines)
          line.UpdateClusterFlyScores(clusterSeriesIndex_, fireUpdate_);
      });

      if (fireUpdate_)
      {
        t.GetAwaiter().OnCompleted(() =>
        {
          foreach (var line in Lines)
          {
            line.FireUpdated(BondField.Fly_ZScore1_1);
            line.FireUpdated(BondField.Fly_ZScore1_2);
            line.FireUpdated(BondField.Fly_ZScore2_1);
            line.FireUpdated(BondField.Fly_ZScore2_2);
          }
        });
      }
      t.Start();
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:23,代码来源:CountryBondSource.cs

示例13: reCalcLevelZScores

    internal void reCalcLevelZScores(int zScore1_, bool fireUpdate_ = true)
    {
      var t = new Task(() =>
      {
        foreach (var line in Lines)
          line.UpdateFocusZScores(zScore1_, false);
      });

      if (fireUpdate_)
      {
        t.GetAwaiter().OnCompleted(() =>
        {
          foreach (var line in Lines)
          {
            line.FireUpdated(BondField.Focus_ZScore1);
          }
        });
      }
      t.Start();
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:20,代码来源:CountryBondSource.cs

示例14: recalcTask

    private Task recalcTask()
    {
      var recalcTaks = new Task(() =>
      {
        try
        {
#if DEBUG
          var sw = new System.Diagnostics.Stopwatch();
          sw.Start();
#endif
          Singleton<CentralEvents>.Instance.FireRecalcEvent();
#if DEBUG
          sw.Stop();
          Logger.Debug(string.Format("Recalc took {0} ms", sw.ElapsedMilliseconds), typeof(MainContainer));
#endif
        }
        catch (Exception ex_)
        {
          Logger.Error("Error recalculating", typeof (MainContainer), ex_);
        }
      });

      recalcTaks.GetAwaiter().OnCompleted(() =>
      {
        try
        {
#if DEBUG
          var sw = new System.Diagnostics.Stopwatch();
          sw.Start();
#endif
          Singleton<CentralEvents>.Instance.FireApplyCalcs();
#if DEBUG
          sw.Stop();
          Logger.Debug(string.Format("applying calcs took {0} ms", sw.ElapsedMilliseconds), typeof(MainContainer));
#endif
        }
        catch (Exception ex_)
        {
          Logger.Error("Error applying calcs", typeof(MainContainer), ex_);
        }
        finally
        {
          timer1.Start();
        }
      });
      return recalcTaks;
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:47,代码来源:MainContainer.cs

示例15: recalcCarry

    private void recalcCarry()
    {
      btnGoRepoRate.Enabled = false;
      var t = new Task(() =>
      {
        m_countryBondSource.RecalcAllCarry(false);
      });

      t.GetAwaiter().OnCompleted(() =>
      {
        foreach (var line in m_countryBondSource.Lines)
        {
          line.FireUpdated(BondField.Focus_Carry);
          line.FireUpdated(BondField.Focus_CarryPlusRoll);
          line.FireUpdated(BondField.Focus_CarryPlusRollOverDuration);
          line.FireUpdated(BondField.Focus_CarryPlusRollOverVol);
        }
        btnGoRepoRate.Enabled = true;
      });

      t.Start();
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:22,代码来源:CountryCurveControl.cs


注:本文中的System.Threading.Tasks.Task.GetAwaiter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。