SignalR invoke does not return when used in an asynchronous method

I'm not sure if this is a SignalR problem or async / await problem. When my client application (WPF) starts up, it does some initialization: -

public async void Initialise()
{
    // Get data from the server - async, as it may be long-running.
    var data = await _hubProxy.Invoke<FooData>("Method1");

    _dataProcessor.ProcessData(data);
}

_dataProcessor - this is a helper class that executes some data with the data passed to it, and then at some point calls another server method using a line similar to: -

var moreData = _hubProxy.Invoke<BarData>("Method2").Result;

None of the classes in the helper class are asynchronous.

( Initialise()) - -. invoke - , , . , , - .

, async/wait Initialise(), . ? -?

( , async void, Initialise() - " ", , ).

+4
1

:

var moreData = _hubProxy.Invoke<BarData>("Method2").Result;

ProcessData a async _hubProxy.Invoke :

var moreData = await _hubProxy.Invoke<BarData>("Method2");

, _dataProcessor.ProcessData Initialise:

await _dataProcessor.ProcessData(data);

, .Result .Wait - .

:

public async void Initialise()
{
    // Get data from the server - async, as it may be long-running.
    var data = await _hubProxy.Invoke<FooData>("Method1").ConfigureAwait(false);

    _dataProcessor.ProcessData(data);
}

ConfigureAwait(false). await , UI. , , . , , .

ConfigureAwait(false) ( ), .Result .Wait .

+4

Source: https://habr.com/ru/post/1532627/


All Articles