my problem is the following: I have my ASP.NET WEB API Server (not Core) with basic SignalR functionality.
Basically on Client connected I return multiple sets of data to the Client
In my DataHub.cs
public class DataHub : Hub
{
public override Task OnConnected()
{
Init(Context.ConnectionId);
return base.OnConnected();
}
private async void Init(string clientId)
{
//takes about 90 seconds which is inacceptable for loading data into my application
await CustomClass.VeryLongTaskAsync();
}
}
In my CustomClass.cs
public class CustomClass
{
private IHubContext _context = GlobalHost.ConnectionManager.GetHubContext<DataHub>();
public async Task VeryLongTaskAsync()
{
for (int i = 0; i<90; i++)
{
SendData(new Image(){
Count = i
});
Thread.Sleep(1000);
}
}
private async Task SendData(Image image)
{
await _context.Clients.Client(_clientID).sendData(image);
}
}
My client uses the following code
public constructor()
{
var _connection = new HubConnection(ServerURI, false);
var _hubProxy = _connection.CreateHubProxy("DataHub");
_hubProxy.On<Image>("sendData", (image) =>
{
//Process Data
});
try
{
await _connection.Start();
}
}
The problem now is that the Client is waiting until the Server-Side function finishes and only then he starts to process the data.
Ideally the Client would start to process the data as soon, as it gets received. And yes the server is sending it async. I confirmed it via Breakpoints.
Is this even possible?
Thanks