我正在使用 xamarin 进行跨平台应用开发。我们使用asure移动服务连接数据库。基本上这个应用程序是用于聊天的,所以我们在.NET Framework中使用了 SignalR 。当应用程序在60秒之后的一段时间内从睡眠状态进入时会崩溃。有没有办法使用 SignalR 连接回来.Issue似乎与 SignalR 。我在哪里需要更新客户端或服务器端的代码。 客户端代码
public class SignalRClient
{
private static string CONNECTION_URL = "http://";
private static TimeSpan CONNECT_TIMEOUT = new TimeSpan(0, 0, 30);
private readonly HubConnection _hubConnection;
private readonly IHubProxy _chatHubProxy;
private static string AuthToken = "";
public string UserID;
public event SignalRConnectionStateChangedDelegate SignalRConnectionStateChangedEvent;
public SignalRClient(string authToken)
{
AuthToken = authToken;
_hubConnection = new HubConnection(CONNECTION_URL);
_hubConnection.Headers["xauth"] = AuthToken;
_hubConnection.TransportConnectTimeout = CONNECT_TIMEOUT;
_hubConnection.Error += ex =>
{
if (SignalRConnectionStateChangedEvent != null)
{
_hubConnection.Stop();
SignalRConnectionStateChangedEvent("Error :" + ex.Message);
}
};
_chatHubProxy = _hubConnection.CreateHubProxy("ChatServer");
}
public async Task Connect(string UserID)
{
if (_hubConnection.State != ConnectionState.Connected)
{
try
{
await _hubConnection.Start();
_hubConnection.StateChanged += (connectionState) =>
{
if (SignalRConnectionStateChangedEvent != null)
{
SignalRConnectionStateChangedEvent(connectionState.NewState.ToString().ToLower());
}
};
}
catch (Exception ex)
{
var message = ex.Message;
}