47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Squirrowse.Client.Service;
|
|
using Squirrowse.Core.Models;
|
|
using Squirrowse.Core.Services;
|
|
|
|
namespace Squirrowse.Client
|
|
{
|
|
public class Worker : IHostedService
|
|
{
|
|
private readonly IConnectionManager _connectionManager;
|
|
private readonly ILogger<Worker> logger;
|
|
private readonly IActionDispatcher _actionDispatcher;
|
|
public Worker(ILogger<Worker> logger, IConnectionManager connectionManager,IActionDispatcher act)
|
|
{
|
|
this.logger = logger;
|
|
_connectionManager = connectionManager;
|
|
_actionDispatcher = act;
|
|
}
|
|
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
await _connectionManager.InitConnection(ConnectionType.Client);
|
|
|
|
}
|
|
catch
|
|
{
|
|
await Task.Delay(1111);
|
|
}
|
|
}
|
|
// await Task.Delay(10000);//for debug
|
|
|
|
}
|
|
|
|
public async Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
await _connectionManager.Disconnect();
|
|
}
|
|
}
|
|
} |