smartirc4net永远监听,无法退出线程 [英] smartirc4net listens forever, can't exit thread

查看:111
本文介绍了smartirc4net永远监听,无法退出线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用smartirc4net库的IRC机器人.我遇到了机器人正在侦听命令的问题,并且我希望它正在运行的线程退出. Listen()命令将永远阻止.如果使用ListenOnce(),则可以将调用置于While(!ShouldExit)循环内,但我必须等待bot触发ListenOnce()的触发.

I have a IRC bot that uses the smartirc4net library. I have run into an issue where the bot is listening for commands and I want the thread it is running on to exit. The Listen() command blocks forever. If I use ListenOnce() I can put the call inside of a While(!ShouldExit) loop, but I have to wait for the bot for something to trigger the ListenOnce().

    protected void irc_OnConnected(object sender, EventArgs e)
    {
        irc.Login(configuration.IRCNick, configuration.IRCNick);

        while (!_shouldDisconnect)
        {
            irc.ListenOnce();
        }

        irc.Disconnect();
    }

作为一种变通方法,当向漫游器发出从父线程发出的断开连接命令时,它会向自身发送一条消息:

As a work around, when the bot is issued a disconnect command from the parent thread, it sends itself a message:

    /// <summary>
    /// Used by the parent thread to disconnect the bot
    /// </summary>
    /// <returns></returns>
    public void Disconnect()
    {
        _shouldDisconnect = true;

        irc.SendMessage(SendType.Message, irc.Nickname, "EXIT YOU STUPID BOT");
    }

这将触发ListenOnce()事件通过while循环返回,然后成功断开连接. 我的处理方式有误吗?是否有一种更清洁的方法可以使漫游器立即断开连接?

This triggers the ListenOnce() event to loop back through the while loop, then successfully disconnect. Am I approaching this incorrectly? Is there a cleaner approach for getting the bot to disconnect immediately?

推荐答案

发现这是最新代码中的错误,并由meebey在

Found that this is a bug in the latest code, confirmed with meebey over at https://github.com/meebey/SmartIrc4net/issues/4

这篇关于smartirc4net永远监听,无法退出线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆