无法使用query.ToObservable(),找不到引用dll

时间:2013-02-21 11:51:00

标签: c# wpf linq

我正在使用Visual Studio 2010 Ultimate来创建WPF应用程序(.net 4.0),我正在阅读来自pluralsight for .NET Reactive Extensions Fundamentals的教程

_http://www.pluralsight.com/training/Courses/TableOfContents/reactive-extensions

显示WPF的一个示例,其中单击按钮时使用简单按钮和只读文本框,文本框的文本附加了使用Enumerable linq查询生成的数字。应用程序保持响应而不会死,因为执行了异步任务。

该应用程序添加了System.CoreEx,System.Observable和System.Reactive

的引用

并假设一行代码就像

var query = from number in Enumerable.Range(1, 25) select number;

var observableQuery = query.ToObservable() // ToObservable() is not seen in intellisense

因为我无法找到并添加引用。

我尝试在谷歌上搜索并安装了

来自

的反应性扩展程序

http://www.microsoft.com/en-in/download/details.aspx?id=26649

http://msdn.microsoft.com/en-us/data/gg577610

但我无法找到所有的dll文件。我在

中的系统中找到了System.Reactive

C:\ Program Files(x86)\ Microsoft Reactive Extensions SDK \ v1.0.10621 \ Binaries.NETFramework \ v4.0

在google上搜索时,我在某处读到System.CoreEx现在包含在System.Reactive中,因此不需要剩下的是System.Observable,我无法找到。

那么我在哪里可以找到dll或者我需要安装什么才能获得该DLL。我甚至尝试过nuget但无法找到。

如果有人可以建议哪里可以获得System.Observable dll。

4 个答案:

答案 0 :(得分:1)

由于版本的变化,我不得不面对问题,但最后在@Lee的帮助和指导下,我可以解决它。谢谢@Lee。我想把这些全部内容带到这里,以便对其他人有帮助。

这是xaml部分:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<StackPanel>
    <Button Name="Start" Click="Start_Click">Start</Button>
    <TextBox Name="Results" Height="250" VerticalScrollBarVisibility="Auto" IsReadOnly="True"/>
</StackPanel>

这是.cs文件编码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.Reactive.Linq;
using System.Reactive.Concurrency;

namespace WpfApplication1
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
        InitializeComponent();
    }

    private static string StringWait(string str)
    {
        Thread.Sleep(10);
        return str;
    }

    private void Start_Click(object sender, RoutedEventArgs e)
    {
        var query = from number in Enumerable.Range(1, 10000000)
                    select StringWait(number.ToString());
        var observableQuery = query.ToObservable(Scheduler.Default);
        observableQuery.ObserveOn(Dispatcher).Subscribe(n => Results.AppendText
            (string.Format("{0}\n",n)));

    }
  }
}

最后这里是我需要的参考资料:

http://i49.tinypic.com/vp7sk7.jpg

答案 1 :(得分:0)

下载Silverlight Toolkit here:然后添加对System.Reactive.dll的引用(默认情况下为 - C:\ Program Files \ Microsoft SDKs \ Silverlight \ v3.0 \ Toolkit \ Oct09 \ Bin)

答案 2 :(得分:0)

ToObservable扩展方法在System.Reactive.Linq.Observable类中定义,该类位于System.Reactive.Linq.dll中。因此,您需要添加对System.Reactive.Linq程序集的引用,并在源文件中添加一个

using System.Reactive.Linq;

指令。

编辑:在回复您的评论时,您似乎想要执行以下操作:

IObservable<string> observableQuery = query.ToObservable();
observableQuery.subscribe(Results.AppendText);

TextBoxBase.AppendText可转换为Action<string>ObservableExtension.Subscribe中定义了一种扩展方法,允许Action<string>订阅IObservable<T> OnNext方法。

要使用此功能,您需要添加对System.Reactive.Core.dll的引用并添加

using System;
源文件中的

指令。

答案 3 :(得分:0)

如果您使用的是最新的.net框架,只需尝试安装此Reactive Extensions (Rx) nuget包,您就应该启动并运行。