最近用到的项目,需要在wince上调用webservice。因为期间需要等待一段时间,所以我打算等待的这段时间加上一个等待的gif图显示,这样可以增加用户体验。gif图的显示,用到微软官方例程的AnimateCtl类,已经实现。我的代码如下:
public Form1()
{
InitializeComponent();
animCtl = new AnimateCtl();
animCtl.Bitmap = new Bitmap(@"loading.png");
animCtl.Location = new Point(50, 80);
this.Controls.Add(animCtl);
}
private void button1_Click(object sender, EventArgs e)
{
animCtl.StartAnimation(94, 100, -1);//开始显示gif图
WebReference.ConfirmService service = new WebReference.ConfirmService();//调webservice
String receiveData = service.LoginCheck("1", "1");
textBox1.Text = receiveData;
}
private void button2_Click(object sender, EventArgs e)
{
animCtl.StopAnimation();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
想法很简单,点击按钮1,先让gif图显示起来,然后在调webservice。可是实际的效果却是,当开始调webservice后,gif图就停止了,等到webservice调用完成,gif图才重新动起来,相当于gif图显示的操作被阻塞了。后来我在网上找资料,说是要异步调用webservice,于是我按照下面的方法http://blog.csdn.net/banmuhuangci/article/details/901723,可是运行却报错:Control.Invoke 必须用于与在独立线程上创建的控件交互。折腾了好久了,实在找不出办法了,求大家帮帮忙啊!!!
------解决思路----------------------
UI控件的操作必须在UI线程中进行,可以利用Control.Invoke方法,将UI操作传递给UI线程处理
------解决思路----------------------
使用
xxoo.Invoke(new action()=>{
//调用webservice
});