【发布时间】:2020-04-16 11:41:06
【问题描述】:
我有一个异步运行的任务,然后我有第二种方法,它需要从异步任务中检索信息。 我无法修改异步任务,所以我想知道是否可以告诉第二种方法等到异步方法完成。
foreach (AgentModel ag in Agents)
{
if (ag.IsEnabledRow == true)
{
if (ag.IsSelected == true)
{
if (ag.selectedMatrice != null)
{
if (ag.selectedWeeks != null)
{
//on vérifie le cycle choisi et on adapte la date en conséquence
semaineAAppliquer(ag);
ag.IsEnabledRow = false;
Task<int> attribuerPlanning = Gestion.AttrPlanning(
_dataService.ParamGlobaux.IDEtablissement,
_dataService.ParamGlobaux.Matricule,
_dataService.ParamGlobaux.ConnectionString,
ag.Matricule, ag.selectedMatrice.IDMatrice, DsCalendrierCongés,
dateDebutCycle, ag.dateFin, HoraireAZero, CompleterPriseVide,
RemplacerRH, JFRepos,
(text, title, buttons) => System.Windows.MessageBox.Show(
text, title, buttons), _progress, DecalageSemaine,
appliquerCouleur, _ToutEtablissement);
}
}
else
{
System.Windows.MessageBox.Show($"Sélectionner une matrice pour" +
$" l'agent {ag.Nom}.");
}
}
}
}
UpdateListeContrats();
attribuerPlanning 方法是异步方法,我希望在不修改方法本身的情况下,它在调用UpdateListeContrats 之前结束。
或者说UpdateListeContrats,在其他方法完成之前不要触发自己。
(目前,updateListeContrats 在没有通过attributerPlanning 方法更新信息的情况下启动。)
【问题讨论】:
-
只是把等待任务属性规划。如果 updateListeContrats 超出当前方法的范围,您可以 .Result for attributePlanning
标签: c# asynchronous task