【问题标题】:How do I get notifications from an asynchronous RIA Services call?如何从异步 RIA 服务调用中获取通知?
【发布时间】:2010-07-27 21:43:48
【问题描述】:

我有一个使用 RIA 服务、Entity Framework 4 和 Silverlight 4 设置的应用程序。它是按照 MSDN 上规定的方式设置的:Walkthrough: Creating a RIA Services Solution

在客户端,此代码将客户实体加载到网格的 ItemsSource 中:

    public MainPage()
    {
        InitializeComponent();

        LoadOperation<Customer> loadOp = this._customerContext.Load(this._customerContext.GetCustomersQuery());
        CustomerGrid.ItemsSource = loadOp.Entities;
    }

对“loadOp.Entities”的调用是异步完成的(由 RIA 服务自动执行)。异步调用完成后如何获取通知?

【问题讨论】:

    标签: silverlight entity-framework asynchronous notifications wcf-ria-services


    【解决方案1】:

    您需要使用回调。我还没有使用过正式版的 RIA,但是在 beta 中是这样使用的。

    public MainPage()
    {
        InitializeComponent();
    
        LoadOperation<Customer> loadOp = this._customerContext.Load(this._customerContext.GetCustomersQuery(),MyCallback,null);
        CustomerGrid.ItemsSource = loadOp.Entities;
    }
    
    private void MyCallback(LoadOperation<Customer> loadOperation)
    {
        //This will be called when the load is complete
    }
    

    【讨论】:

    • 谢谢,正是我想要的。在 RIA 服务的发布版本中,Load 需要一个额外的参数,例如this._customerContext.Load(this._customerContext.GetCustomersQuery(),MyCallback, null);
    • 是的,我忘记了 objectState 参数。这是所有 .NET 中异步调用的一个非常标准的论点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多