2015-04-03 31 views
0

問題很簡單。我從網站http://rxwiki.wikidot.com/101samples#toc0這裏找到這段代碼。無法等待system.IObservable。*** Cx中的接收錯誤#

public static async void StartBackgroundWork() 
     { 
      Console.WriteLine("Shows use of Start to start on a background thread:"); 
      var o = Observable.Start(() => 
      { 
       //This starts on a background thread. 
       Console.WriteLine("From background thread. Does not block main thread."); 
       Console.WriteLine("Calculating..."); 
       Thread.Sleep(1000); 
       Console.WriteLine("Background work completed."); 
      }); 
      **await o.FirstAsync();** // subscribe and wait for completion of background operation. If you remove await, the main thread will complete first. 
      Console.WriteLine("Main thread completed."); 
     } 

但是,當我把它粘貼到我的項目中,出現「無法等待system.IObservable」的錯誤。它出什麼問題了?我怎樣才能運行這段代碼?鑑於我對Rx和C#不太熟悉,如果問題太蠢,請原諒我。

回答

1

您可能鏈接到.NET 4.0的Rx DLL而不是.NET 4.5。

如果您從Nuget獲取包,請嘗試使用Nuget控制檯中的命令「Update-Package -reinstall」重新安裝包。有關更多信息,請參閱:http://docs.nuget.org/consume/reinstalling-packages

您可以通過轉到項目的Reference/System.Reactive.Core屬性選項卡來檢查當前使用的版本,並檢查「Path」屬性。它應該包含 「net45」 如下:

+++ \包\ RX-Core.2.2.5 \ LIB \ net45 \ System.Reactive.Core.dll

+0

謝謝您的回答。正如你所說,我更改當前使用的版本到工具欄上的Debug45,我真的有用。 @nikoniko – Tyoshi 2015-04-03 05:28:28

相關問題