2
我正嘗試使用Reactive Extensions編寫代碼來處理異步調用,其中啓動方法和完成的事件都是靜態的。我不能使用如何使用帶有靜態事件的Observable.FromEvent?
var languageSetsLoaded = Observable
.FromEvent<LoadLanguageSetsCompletedEventArgs>(
LanguageManager, "LanguageSetsLoaded")
爲LanguageManager是一個靜態類,而不是一個實例,所以我試圖
var languageSetsLoaded = Observable
.FromEvent<LoadLanguageSetsCompletedEventArgs>(
h => LanguageManager.LanguageSetsLoaded += h,
h => LanguageManager.LanguageSetsLoaded -= h)
,但給人的語法錯誤「無法轉換lambda表達式鍵入‘對象’,因爲它不是委託類型「。該事件的聲明從而
public delegate void LoadLanguageSetsCompletedHandler(LoadLanguageSetsCompletedEventArgs e);
public static event LoadLanguageSetsCompletedHandler LanguageSetsLoaded = delegate { };
所以我認爲這是一個委託類型,也許是事實,這是靜態的是生產誤導性的錯誤描述。
是他們的一些方法來做到這一點,或者我只需要堅持這樣的非反應式代碼?
private void ChangeLanguage(string languageCode)
{
LanguageManager.LanguageSetsLoaded += OnLanguageSetsLoaded;
LanguageManager.LoadLanguageSets(languageCode, BaseApp.InTranslationMode);
}
private void OnLanguageSetsLoaded(LoadLanguageSetsCompletedEventArgs e)
{
LanguageManager.LanguageSetsLoaded -= OnLanguageSetsLoaded;
OnPropertyChanged("DummyLanguageResource");
}