如何通过C#正确处理sigterm Signs Signs Signable?

发布于 2025-02-06 13:59:59 字数 704 浏览 0 评论 0原文

在用C#编写的电报机器人中,我使用以下代码来捕获机器人关闭(sigterm呼叫):

using Mono.Unix;
using Mono.Unix.Native;
public class UnixExitSignal
{
    private event EventHandler OnExecute;
    private readonly UnixSignal[] signals = new UnixSignal[]{
    new UnixSignal(Signum.SIGTERM),
};
    public UnixExitSignal(EventHandler OnExecute)
    {
        this.OnExecute = OnExecute;
    }
    public void Wait()
    {
        _ = Task.Factory.StartNew(() =>
        {
            _ = UnixSignal.WaitAny(signals, -1);
            OnExecute(null, EventArgs.Empty);
        });
    }
}

一定时间后,我遇到此错误:

冲突:其他getupdates请求终止;确保只有一个bot实例正在运行

我该如何正确完成任务,以便将来不遇到上述错误?

In a telegram bot written in c#, I use the following code to catch the bot shutting down(SIGTERM call):

using Mono.Unix;
using Mono.Unix.Native;
public class UnixExitSignal
{
    private event EventHandler OnExecute;
    private readonly UnixSignal[] signals = new UnixSignal[]{
    new UnixSignal(Signum.SIGTERM),
};
    public UnixExitSignal(EventHandler OnExecute)
    {
        this.OnExecute = OnExecute;
    }
    public void Wait()
    {
        _ = Task.Factory.StartNew(() =>
        {
            _ = UnixSignal.WaitAny(signals, -1);
            OnExecute(null, EventArgs.Empty);
        });
    }
}

After a certain amount of time I meet this error:

Conflict: terminated by other getUpdates request; make sure that only one bot instance is running

How can I correctly complete the task so as not to meet the above error in the future?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文