English 中文(简体)
How can I update UI when Observable.Context is not available?
原标题:

I have a WinFrom App, use synchronous method to download string from a url, and use Rx ToAsync Method to make it asynchronous and get the observable result, and when the result comes I show it on the Form.

Yesterday, I updated Rx to the latest release, and it was told that "Observable does not contain a definition of Context". I tried comment this line, the codes threw an exception that "Cross-thread operation not valid: Control tbx_Reference accessed from a thread other than the thread it was created on."

I want to show the asynchronous result using Subscribe method. How can I fix this problem? thanks very much.

public static IObservable<TResult> DoWorkAsync(TParameter parameter,
        Func<TParameter,TResult> actionSync)
    {
        Observable.Context = SynchronizationContext.Current;

        Func<TParameter, IObservable<TResult>> ActionAsync =  actionSync.ToAsync();

        IObservable<TResult> results = from result in ActionAsync(parameter)
                                       select result;

        return results;
    }
最佳回答

For your return statement, try:

return results.ObserveOnDispatcher();
问题回答

暂无回答




相关问题
Split an IObservable and then combine after processing?

After experimenting with IObservables, I ve decided to test them for the processing of incoming messages over a message bus. Essentially I get an IObservable<Request> and the Request contains ...

Silverlight Toolkit DragDrop on WPF

Do Microsoft actually provide a build of Rx / Silverlight Toolkit DragDrop that "just works" on WPF? From what I can tell the Rx DragDrop stuff is only available in the SL Toolkit (not WPF). The SL ...

How can I update UI when Observable.Context is not available?

I have a WinFrom App, use synchronous method to download string from a url, and use Rx ToAsync Method to make it asynchronous and get the observable result, and when the result comes I show it on the ...

Reactive Extensions (Rx) + MVVM =?

One of the main examples being used to explain the power of Reactive Extensions (Rx) is combining existing mouse events into a new event representing deltas during mouse drag: var mouseMoves = from ...

热门标签