简体   繁体   English

在执行异步RIA Services调用时,哪个线程是执行的回调?

[英]Which thread is the callback executing on when performing an asynchronous RIA Services call?

I'm using a RIA Services DomainContext in a Silverlight 4 app to load data. 我在Silverlight 4应用程序中使用RIA Services DomainContext来加载数据。 If I'm using the context from the UI thread, is the callback always going to be on the UI thread? 如果我正在使用UI线程中的上下文,那么回调总是会在UI线程上吗?

Or put another way, is the callback always on the same thread as the call? 或换句话说,回调是否始终与呼叫在同一个线程上?

Some example code below illustrating the scenario... 下面的一些示例代码说明了该场景......

    private void LoadStuff()
    {
        MyDomainContext context = new MyDomainContext ();
        context.Load(context.GetStuffQuery(), op =>
        {
            if (!op.HasError)
            {
                // Use data.

                // Which thread am I on?
            }
            else
            {
                op.MarkErrorAsHandled();

                // Do error handling

            }
        }, null
        );
    }

If you execute the Load-Method of the DomainContext on the UI-Thread, then is the callback also executed on the UI-Thread. 如果在UI-Thread上执行DomainContext的Load-Method,那么回调也会在UI-Thread上执行。

This is also true, when you use the Completed-Event of the LoadOperation returned by Load. 当您使用Load返回的LoadOperation的Completed-Event时也是如此。

LoadOperation<Stuff> operation = context.Load(context.GetStuffQuery());
operation.Completed += (o, e) {
  if (!operation.HasError) {
    // Use data.

    // Which thread am I on?
  }
  else {
    op.MarkErrorAsHandled();
    // Do error handling
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM