Example #1
0
        /// <summary>
        /// Shuts down the client, disconnecting from the IRC server, and shutting down any of our threads.
        /// </summary>
        public void Stop()
        {
            lock (controlSyncLock)
            {
                // Ensure client is killed dead
                if (client != null)
                {
                    if (client.IsConnected)
                    {
                        try
                        {
                            client.Disconnect();
                        }
                        catch (Exception) { }
                    }
                }

                if (client != null)
                {
                    client.Dispose();
                    client = null;
                }

                // Switch status & raise event if we aren't already in stopped state
                if (Status != ClientStatus.Stopped)
                {
                    TmiLog.Log("Stopping client...");

                    if (OnStopped != null)
                    {
                        OnStopped.Invoke(this, new EventArgs());
                    }
                }

                Status = ClientStatus.Stopped;

                // Kick the queue thread so it quits faster
                if (channelJoinQueueThread != null)
                {
                    try
                    {
                        channelJoinQueueThread.Interrupt();
                    }
                    catch (Exception) { }

                    channelJoinQueueThread = null;
                }
            }
        }
Example #2
0
        private static async Task MainAsync(string[] args)
        {
            using (var client = new TwitchIrcClient("irc.chat.twitch.tv", 6667))
            {
                client.LoggedIn            += Client_LoggedIn;
                client.ChannelJoined       += Client_ChannelJoined;
                client.UserJoined          += Client_UserJoined;
                client.IrcMessageReceived  += Client_IrcMessageReceived;
                client.ChatMessageReceived += Client_ChatMessageReceived;
                client.UserSubscribed      += Client_UserSubscribed;
                client.Disconnected        += Client_Disconnected;

                await client.ConnectAsync("username", "oauth:token");

                Console.ReadLine();
                client.Disconnect();
            }
            Console.ReadLine();
        }