【问题标题】:Reactive extensions Observable.Using and WCF async call反应式扩展 Observable.Using 和 WCF 异步调用
【发布时间】:2012-03-14 04:25:40
【问题描述】:

我无法理解如何使用 Observer.Using

我有以下代码

    public void Test()
    {
        Observable.Using(
            () => new GFSClientServiceClient(),
            (c) => ObservableGetParameters(c))
                .Subscribe(
                    (response) => Debug.Print("response"),
                    (ex) => Debug.Print("{0} error: {1}", Name, ex.Message),
                    () => Debug.Print("{0} complete", Name)
                );
    }

    private static Func<IObservable<Dictionary<string, Dictionary<string, string>>>> ObservableGetParameters(GFSClientService.GFSClientServiceClient client)
    {
        return Observable.FromAsyncPattern<Dictionary<string, Dictionary<string, string>>>(client.BeginGetParameters, client.EndGetParameters);
    }

我似乎无法让 using 子句起作用。它一直告诉我无法推断类型,但我不明白为什么?有人知道吗?

【问题讨论】:

    标签: c# system.reactive


    【解决方案1】:

    编辑:

    我的第一个答案是错误的。对于那个很抱歉。你可能想做这样的事情:

    public void Test() 
    { 
       Observable.Using(() => new Client(), 
            (c) => ObservableGetParameters(c))
                        .Subscribe((response) => Debug.Print("response"), 
                       (ex) => Debug.Print("{0} error: {1}", "name", ex.Message), 
                       () => Debug.Print("{0} complete", "name"));
    }
    private static IObservable<Dictionary<string, Dictionary<string, string>>> ObservableGetParameters(Client client) 
    {
      return Observable.FromAsyncPattern<Dictionary<string, Dictionary<string, string>>>(client.BeginGetParameters, client.EndGetParameters)(); 
      }
    public class Client : IDisposable {
     public IAsyncResult BeginGetParameters(AsyncCallback cb, object o) { 
       return default(IAsyncResult);
    }
    public Dictionary<string, Dictionary<string, string>> EndGetParameters(IAsyncResult res) {
      return default(Dictionary<string, Dictionary<string, string>>);
    }
    public void Dispose() {}
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      相关资源
      最近更新 更多