PDA程序 点击登录按钮显示提示信息
PDA程序 点击登录按钮 与WebService进行通信,因为PDA引用WebService不能生成异步方法,所以在通信过程中会卡,但我又想在这个过程中显示个提示信息,提示正在登录。如下图:
在实现的过程中还报了一个错误:Control.Invoke 必须用于与在独立线程上创建的控件交互.顺带一起解决了
解决代码:
1 using System; 2 using System.Linq; 3 using System.Collections.Generic; 4 using System.ComponentModel; 5 using System.Data; 6 using System.Drawing; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Net; 10 using System.Threading; 11 namespace PDAApp 12 { 13 public partial class FormLogin : Form 14 { 15 public FormLogin() 16 { 17 InitializeComponent(); 18 } 19 private delegate void NewDel(); 20 public void ThreadTest() 21 { 22 Thread thread; 23 ThreadStart thStart = new ThreadStart(start); 24 thread = new Thread(thStart); 25 thread.Start(); 26 } 27 private void start() 28 { 29 if (InvokeRequired) 30 { 31 BeginInvoke(new NewDel(Login)); 32 } 33 } 34 private void Login() 35 { 36 //登录代码 37 38 } 39 private void btnLogin_Click(object sender, EventArgs e) 40 { 41 42 lblLoginMsg.Text = "正在进行登录,需要一定的时间,请耐心等待......"; 43 ThreadTest(); 44 } 45 46 private void btnExit_Click(object sender, EventArgs e) 47 { 48 this.Close(); 49 this.Dispose(true); 50 } 51 } 52 }
Android 成长之路