Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 在WCF调用之前引入延迟是否有更可取的方法_Multithreading_Silverlight_Wcf - Fatal编程技术网

Multithreading 在WCF调用之前引入延迟是否有更可取的方法

Multithreading 在WCF调用之前引入延迟是否有更可取的方法,multithreading,silverlight,wcf,Multithreading,Silverlight,Wcf,当我的用户更改数据表单的CurrentItem时,我需要转到服务器以获取附加数据。很可能用户可以在找到所需的项目之前滚动浏览多个项目。在获取数据之前,我想先睡500毫秒 SDK或toolkit中是否已经有一个组件(如后台工作程序)可以在500毫秒睡眠完成后帮助返回UI线程进行WCF异步调用?似乎如果我不这样做,而是尝试在睡眠线程上调用WCF async方法,那么完成的事件将在睡眠线程而不是UI线程上触发,这当然不好。我认为您的想法可能有点偏离轨道。我不知道为什么您觉得需要返回UI线程才能进行as

当我的用户更改数据表单的CurrentItem时,我需要转到服务器以获取附加数据。很可能用户可以在找到所需的项目之前滚动浏览多个项目。在获取数据之前,我想先睡500毫秒


SDK或toolkit中是否已经有一个组件(如后台工作程序)可以在500毫秒睡眠完成后帮助返回UI线程进行WCF异步调用?似乎如果我不这样做,而是尝试在睡眠线程上调用WCF async方法,那么完成的事件将在睡眠线程而不是UI线程上触发,这当然不好。

我认为您的想法可能有点偏离轨道。我不知道为什么您觉得需要返回UI线程才能进行asych调用。通常,您在BG线程上做尽可能多的工作,并且只有在得到结果时才封送回UI线程(通过)

为此,我通常使用a:

public class MyViewModel
{
    private readonly Timer refreshTimer;

    public MyViewModel()
    {
        this.refreshTimer = new Timer(this.DoRefresh);
    }

    public object CurrentItem
    {
        get { ... }
        set
        {
            ...
            Invalidate();
        }
    }

    // anything that should invalidate the data should wind up calling this, such as when the user selects a different item
    private void Invalidate()
    {
        // 1 second delay
        this.refreshTimer.Change(1000, Timeout.Infinite);
    }

    private void DoRefresh()
    {
        // make the async call here, with a callback of DoRefreshComplete
    }

    private void DoRefreshComplete()
    {
        // update the UI here by way of the Dispatcher
    }
}

我想你的想法可能有点偏离正轨。我不知道为什么您觉得需要返回UI线程才能进行asych调用。通常,您在BG线程上做尽可能多的工作,并且只有在得到结果时才封送回UI线程(通过)

为此,我通常使用a:

public class MyViewModel
{
    private readonly Timer refreshTimer;

    public MyViewModel()
    {
        this.refreshTimer = new Timer(this.DoRefresh);
    }

    public object CurrentItem
    {
        get { ... }
        set
        {
            ...
            Invalidate();
        }
    }

    // anything that should invalidate the data should wind up calling this, such as when the user selects a different item
    private void Invalidate()
    {
        // 1 second delay
        this.refreshTimer.Change(1000, Timeout.Infinite);
    }

    private void DoRefresh()
    {
        // make the async call here, with a callback of DoRefreshComplete
    }

    private void DoRefreshComplete()
    {
        // update the UI here by way of the Dispatcher
    }
}