该场景是我正在使用sendgrid api 发送1000多封电子邮件。 并且我已经使用 signalR 来通知用户,在发送电子邮件时已经发送了多少电子邮件,有多少未发送。 三分钟后,信号器连接断开。 我收到错误消息,由于闲置超过30秒而导致连接断开。
我尝试将keep-alive属性设置为null,并且还设置了5天, 连接超时相同。当我设置这些属性时,我没有收到错误消息。但是Connection断开连接并重新开始,从零点开始发送电子邮件的过程。
这是我的代码
$(function () {
///Reference the auto-generated proxy for the hub.
var progress = $.connection.progressHub;
// Create a function that the hub can call back to display messages.
// Function To nitify the user of email state
progress.client.AddProgress = function (message, percentage, delivered, error) {
ProgressBarModal("show", delivered, error, message);
$("#ProgressMessage").css("width", percentage + "%");
$('#ProgressMessage').text(percentage + "%");
if (percentage == "100%") {
ProgressBarModal();
}
};
$.connection.hub.start({ pingInterval: null }).done(function () {
var connectionId = $.connection.hub.id;
});
$.connection.hub.connectionSlow(function () {
console.log("connectionSlow");
});
$.connection.hub.reconnecting(function () {
console.log("Reconnecting Hub ");
});
$.connection.hub.disconnected(function () {
if ($.connection.hub.lastError) {
alert("Disconnected. Reason: " + $.connection.hub.lastError.message);
}
// Restart connection after 5 seconds.
setTimeout(function () {
$.connection.hub.start();
}, 6);
});
});
中心代码
public class ProgressHub : Hub
{
public static void SendProgress(string progressMessage, int progressCount, int totalItems, int delivered, int error)
{
try
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<ProgressHub>();
//CALCULATING PERCENTAGE BASED ON THE PARAMETERS SENT
var percentage = (progressCount * 100) / totalItems;
progressMessage = "Processed Mails " + progressCount + " out of " + totalItems + ".";
//PUSHING DATA TO ALL CLIENTS
context.Clients.All.AddProgress(progressMessage, percentage.ToString(), delivered, error);
}
catch (Exception ex)
{
throw;
}
}
}
我在c#控制器的for循环中调用此函数,每发送100封邮件(无论电子邮件状态如何),循环就会休眠1分钟。
ProgressModalUiUpdate(progressbarResult, campaignSessionid, errorCount, hubCount, totalNoOfMailsToBeSend);
谁能帮我解决问题。