C# Windows Mobile 6.1异步web服务调用和更新UI的问题
我正在调用一个异步web服务调用并从中获取结果,该调用提供了一个对象数组以显示在手持windows mobile上的网格中 有一次,我使用InvokedRequired和Invoke正确更新了UI。现在,我第一次运行emulator和VisualStudio2008时,它将正常工作,但后续调用似乎挂起调用方法调用,代码中没有其他断点 此应用程序正在使用.Net CF 2.0 SP1,目标是WinMo 6.1设备。我最近从运行XP的虚拟开发环境切换到运行Vista的主机笔记本电脑C# Windows Mobile 6.1异步web服务调用和更新UI的问题,c#,user-interface,web-services,asynchronous,C#,User Interface,Web Services,Asynchronous,我正在调用一个异步web服务调用并从中获取结果,该调用提供了一个对象数组以显示在手持windows mobile上的网格中 有一次,我使用InvokedRequired和Invoke正确更新了UI。现在,我第一次运行emulator和VisualStudio2008时,它将正常工作,但后续调用似乎挂起调用方法调用,代码中没有其他断点 此应用程序正在使用.Net CF 2.0 SP1,目标是WinMo 6.1设备。我最近从运行XP的虚拟开发环境切换到运行Vista的主机笔记本电脑 private
private delegate void UpdateGrid(WebServiceItems[] items);
private void DoGridUpdate(WebServiceItems[] items)
{
// Choose the correct grid based on the tab index
DataGrid grid;
if (tabSelectedIndex == 0)
grid = gridA;
else
grid = gridB;
if (grid.InvokeRequired)
{
grid.Invoke(new UpdateGrid(DoGridUpdate), new object[] { items });
return;
}
Cursor.Current = Cursors.Default;
grid.DataSource = items;
if (items.Length > 0)
{
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = items.GetType().Name;
DataGridTextBoxColumn column = new DataGridTextBoxColumn();
column.Width = 230;
column.MappingName = "Column1";
column.HeaderText = "Column1";
tableStyle.GridColumnStyles.Add(column);
column = new DataGridTextBoxColumn();
column.Width = 70;
column.MappingName = "Column2";
column.HeaderText = "Column2";
tableStyle.GridColumnStyles.Add(column);
grid.TableStyles.Clear();
grid.TableStyles.Add(tableStyle);
}
}
我忘记了这个问题,但找到了解决办法。我来自ASP.NET的背景,当时还没有意识到如何保持服务的范围,我很惊讶它能工作
该服务的声明在button onclick事件中,因此我将其移动到表单构造函数中,并使该服务成为表单的全局服务,以便所有方法都可以访问它,并且现在一切都按预期工作。我将if块代码更改为此。它工作过一次,所以我停止调试,重新启动,现在它卡在了系统中!result.IsCompleted循环。if(this.invokererequired){IAsyncResult result=this.BeginInvoke(new UpdateGrid(DoGridUpdate),new object[]{items});while(!result.IsCompleted)System.Threading.Thread.Sleep(100);this.EndInvoke(result);return;}