当前位置: 首页>>代码示例>>C#>>正文


C# DiscordClient.Dispose方法代码示例

本文整理汇总了C#中Discord.DiscordClient.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.Dispose方法的具体用法?C# DiscordClient.Dispose怎么用?C# DiscordClient.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Discord.DiscordClient的用法示例。


在下文中一共展示了DiscordClient.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectAsync

        private static async void ConnectAsync()
        {
            State = ConnectionState.Connecting;

            Client = new DiscordClient();

            Client.MessageReceived += MessageHandler.HandleIncomingMessage;
            Client.MessageUpdated += MessageHandler.HandleEdit;

            Console.WriteLine("Connecting...");
            try
            {
                await Client.Connect(Config.Token, TokenType.Bot);
                Client.SetGame("3v.fi/l/BotVentic");
                State = ConnectionState.Connected;
                Console.WriteLine("Connected!");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine("Reconnecting...");
                State = ConnectionState.Disconnected;
                Client.Dispose();
            }
        }
开发者ID:3ventic,项目名称:BotVentic,代码行数:25,代码来源:Program.cs

示例2: button1_Click

        private async void button1_Click(object sender, EventArgs e)
        {
            lock (o)
            {
                if (button1Clicked) return;
                else button1Clicked = true;
            }

            DiscordClient client = new DiscordClient();

            try
            {
                textBox1.Enabled = false;
                textBox2.Enabled = false;
                this.Text = "Logging in...";

                await client.Connect(textBox1.Text, textBox2.Text);

                if (client.State == ConnectionState.Connected || client.State == ConnectionState.Connecting)
                {
                    if (!checkBox1.Checked)
                    {
                        textBox1.Text = "";
                        textBox2.Text = "";
                    }
                    Properties.Settings.Default.Email = textBox1.Text;
                    Properties.Settings.Default.Password = textBox2.Text;
                    Properties.Settings.Default.Remember = checkBox1.Checked;
                    Properties.Settings.Default.Save();

                    // The best way to wait of course
                    DateTime start = DateTime.Now;
                    while (client.State != ConnectionState.Connected)
                    {
                        System.Threading.Thread.Sleep(10);

                        var delta = DateTime.Now - start;
                        if (delta >= TimeSpan.FromSeconds(TIMEOUT))
                            throw new TimeoutException("Login timed out. Either the email/password provided is incorrect or the program can not connect to Discord.");
                        else if (delta < TimeSpan.Zero)
                            throw new Exception("The time on this computer was changed.");
                    }

                    MainForm main = new MainForm(client);
                    main.Owner = this;
                    main.Show();
                    this.Hide();
                }
                else
                {
                    throw new Exception("Login failed.");
                }
            }
            catch (Exception ex)
            {
                textBox1.Enabled = true;
                textBox2.Enabled = true;
                this.Text = "DiscordStatusUpdater";
                MessageBox.Show(ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace, "Failed to login", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                Console.WriteLine(ex.ToString() + Environment.NewLine + ex.StackTrace);
                client.Dispose();
            }

            lock (o)
            {
                button1Clicked = false;
            }
        }
开发者ID:Dutchman97,项目名称:DiscordStatusUpdater,代码行数:68,代码来源:LoginForm.cs


注:本文中的Discord.DiscordClient.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。