我有一個奇怪的問題。我想在同步函數調用中等待結束異步調用。在其他項目中,我成功使用了ResetEvents,但在sl中它似乎沒有工作。silverlight。等待結束異步方法同步方法
//Sync call save some value in storage
public static void SaveValue(string key, object value, bool encrypted)
{
if (encrypted)
{
isEncrypting = true;
var Registrator = new RegistratorClient();
Registrator.EncryptCompleted +=Registrator_EncryptCompleted;
Registrator.EncryptAsync(obj); //async call
while (isEncrypting)
Thread.Sleep(10);
return;
}
...
}
static void Registrator_EncryptCompleted(object sender, EncryptCompletedEventArgs e)
{
if (String.IsNullOrEmpty(fieldToSave))
return;
App Appvars = Application.Current as App;
if (Appvars.Settings.Contains(fieldToSave))
Appvars.Settings[fieldToSave] = e.Result;
else
Appvars.Settings.Add(fieldToSave, e.Result);
isEncrypting = false;
}
這種方法是不是太工作:(請幫助什麼是錯