且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何等待,直到事件不会阻塞执行在UI完成

更新时间:2021-09-03 09:47:22

主要的问题是,执行查询语义不相关的服务层得到初始化,所以它没有任何意义,把查询中的层初始化事件的监听器方法。把查询code在运行时,地图图层初始化事件处理程序的方法是不符合逻辑的。

The main problem was that executing a query is not semantically related to a service layer getting initialized and so it didn't make sense to put the query in the layer initialization event's listener method. Putting query code in an event handler method that runs when a map layer is initialized isn't logical.

我还没有开始考查.NET 4.5任务具有平行库中的任何严肃的深度,所以我已经决定这样做。

I haven't yet started on examining the .NET 4.5 Task Parrallel library in any serious depth, so I've decided to do this.

在事件处理监听器的方法,我打了一个电话,以这样的查询方法。

In the event handling listener method, I made a call to the query method like this.

private void DynamicMapServiceLayer_Initialized(object sender, System.EventArgs evArgs) 
{ 
   QueryUrlParameters();
} 

然后我把参数查询过程中,有一个相匹配的责任名称的方法:

And then I keep the parameter querying procedure in a method that has a name that matches its responsibility:

public static void QueryUrlParameters()
{
   Query query = GetParameterQuery();
   QueryTask queryTask = new QueryTask(GetRestURL(dynMapServLayer));
   queryTask.ExecuteCompleted += GraphicQueryTask_ExecuteCompleted;
   queryTask.Failed += QueryTask_Failed;
   queryTask.ExecuteAsync(query);   
}

这是还没有这样一个很好的解决方案。照片 我将有preferred等待已初始化事件更优雅的方式;但看起来,这是我的一切,现在。

This is still not such a great solution.
I would have preferred a more elegant way of waiting for the event to have initialized; but it looks like this is all I've got for now.