消息循环! [英] Message loop!

查看:92
本文介绍了消息循环!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直收到以下错误:我已经按照应有的方式更改了所有内容 


在单个线程上启动第二个消息循环不是有效的操作。用户Form.ShowDialog而不是。


我成功登录后即可得到上述消息!


        private void btnLogin_Click_1(object sender,EventArgs e)


        {            

            COMMAND = new MySqlCommand(Query,MySqlConn);

            if(txtUsername.Text =="" || txtPassword.Text =="")

            {

                MessageBox.Show("请提供用户名和密码");

               返回;

            }¥b $ b           试试
            {

                //创建SqlConnection

                MySqlConnection con = new MySqlConnection(cs);

                MySqlCommand cmd = new MySqlCommand(&SELECT userlevel FROM ***。rc *** on WHERE username ='" + txtUsername.Text +"'and userpassword ='" + txtPassword.Text +"'" ,
con);

                MySqlDataAdapter adapt = new MySqlDataAdapter(cmd);

                DataTable ds = new DataTable();

                adapt.Fill(ds);

                //如果count等于1,则显示frmMain形式

                if(ds.Rows.Count == 1)

                {

                    MessageBox.Show("登录成功!");

                    this.Hide();

                    GUImain gui = new GUImain(ds.Rows [0] [0] .ToString());

                    // gui = new GUImain();

                      Application.Run(gui);

                    gui.Show();

                    //((Form)fm).Controls [" label1"]。Text = ds.Rows [0] [0] .ToString();

                }¥b $ b               否则

                {

                    MessageBox.Show(" Login Failed!");

                }¥b $ b            }¥b $ b            catch(例外情况)

            {

                MessageBox.Show(ex.Message);

            }¥b $ b        }

解决方案

因为你在应用程序中运行Application.Run 。在同一个线程上运行


使用 


Application.Restart() 



I keep getting the following error I have changed everything the way it should be and well 

Starting a second message loop on a single thread is not a valid operation. User Form.ShowDialog instead.

soon as I login successfully I get the above message!

        private void btnLogin_Click_1(object sender, EventArgs e)

        {            
            COMMAND = new MySqlCommand(Query, MySqlConn);
            if (txtUsername.Text == "" || txtPassword.Text == "")
            {
                MessageBox.Show("Please provide UserName and Password");
                return;
            }
            try
            {
                //Create SqlConnection
                MySqlConnection con = new MySqlConnection(cs);
                MySqlCommand cmd = new MySqlCommand("SELECT userlevel FROM ***.rc***on WHERE username='" + txtUsername.Text + "' and userpassword='" + txtPassword.Text + "'", con);
                MySqlDataAdapter adapt = new MySqlDataAdapter(cmd);
                DataTable ds = new DataTable();
                adapt.Fill(ds);
                //If count is equal to 1, than show frmMain form
                if (ds.Rows.Count == 1)
                {
                    MessageBox.Show("Login Successful!");
                    this.Hide();
                    GUImain gui = new GUImain(ds.Rows[0][0].ToString());
                    //gui = new GUImain();
                     Application.Run(gui);
                    gui.Show();
                    // ((Form)fm).Controls["label1"].Text = ds.Rows[0][0].ToString();
                }
                else
                {
                    MessageBox.Show("Login Failed!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

解决方案

Its because you run Application.Run inside the application.Run on the same thread

use 

Application.Restart() 



这篇关于消息循环!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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