Esempio n. 1
0
 private void StartProcess(ServiceThread thread, Button button)
 {
     button.Text      = button.Text.Replace("Start ", "Stop ");
     button.ForeColor = Color.Red;
     try
     {
         button.Enabled = false;
         thread.Start();
     }
     finally
     {
         button.Enabled = true;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Connect to twitch service with provided username and password.
        /// </summary>
        /// <param name="channel">Channel for the bot to write messages and/or moderate.</param>
        /// <remarks>Passwords meaning your provided token.</remarks>
        /// <returns>True whether could connect otherwise false.</returns>
        public async Task ConnectAsync(string channel)
        {
            try
            {
                ServiceThread st = new ServiceThread(channel);
                st.Thread = new Thread(async() =>
                {
                    try
                    {
                        while (!st.CancellationToken.IsCancellationRequested)
                        {
                            if (TCPClient.Available > 0 || Reader.Peek() >= 0)
                            {
                                var message = await Reader.ReadLineAsync();
                                OnMessageReceived(new MessageReceivedEventArgs(message, channel));
                            }

                            st.CancellationToken.Token.ThrowIfCancellationRequested();
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        Debug.WriteLine($"[*] Thread ({st.Channel}) has stopped working, through a cancellation request.");
                    }
                });

                st.Start();

                // join chatroom
                await SendMessageAsync(
                    message : $"JOIN #{channel.ToLower()}",
                    systemMessage : true
                    );

                Threads.Add(st);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Esempio n. 3
0
 protected override void OnStart(string[] args)
 {
     //System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle;
     _thread = GetServiceThread();
     _thread.Start();
 }