本文整理汇总了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);
}
示例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();
}
示例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();
}
示例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();
}
示例5: Exception
public static Exception Exception(Task task)
{
Guard.ArgumentNotNull("task", task);
try
{
task.GetAwaiter().GetResult();
return null;
}
catch (Exception ex)
{
return ex;
}
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}