【发布时间】:2019-06-05 19:04:53
【问题描述】:
imap idle 的 github 页面上的示例程序在连接到 gmail imap 服务器 9 分钟后会引发对等方重置连接。 在连接到移动热点互联网连接的树莓派 3 上运行 dotnet core 控制台应用程序
该代码适用于任何其他网络或个人电脑。 只有当树莓派连接到移动热点时它才起作用
代码在第一次连接时运行良好。它只会在这个单一功能上中断并引发对等方的连接重置
private void IdleLoop(object state) {
IdleState idle = (IdleState) state;
lock (idle.Client.SyncRoot) {
while (!idle.IsCancellationRequested) {
using (CancellationTokenSource timeout = new CancellationTokenSource()) {
using (Timer timer = new Timer(9 * 60 * 1000)) {
timer.Elapsed += (sender, e) => timeout.Cancel();
timer.AutoReset = false;
timer.Enabled = true;
try {
idle.SetTimeoutSource(timeout);
if (idle.Client.Capabilities.HasFlag(ImapCapabilities.Idle)) {
//TODO ERROR
idle.Client.Idle(timeout.Token, idle.CancellationToken);
}
else {
Logger.Log("Issuing NoOp command to IMAP servers...");
idle.Client.NoOp(idle.CancellationToken);
WaitHandle.WaitAny(new[] { timeout.Token.WaitHandle, idle.CancellationToken.WaitHandle });
Logger.Log("NoOp completed!");
}
}
catch (OperationCanceledException) {
break;
}
catch (ImapProtocolException) {
break;
}
catch (ImapCommandException) {
break;
}
finally {
idle.SetTimeoutSource(null);
}
}
}
}
}
}
【问题讨论】: