How to wait until an event is finished without blocking execution in the UI

前端 未结 2 1925
甜味超标
甜味超标 2021-01-26 07:38

I’m trying to figure out how can I make sure that the event has fired before letting the rest of the code run.

I hook up an event like this:

public stati         


        
2条回答
  •  梦谈多话
    2021-01-26 07:51

    The async/await is designed to solve your particular set of problems.

    You'll need to turn the WCF calls into Tasks. Then it is a matter of

    public static async void QueryUrlParameters()
    {
        await dynMapServLayer.EnsureIsInitialized();
    
        Query query = GetParameterQuery();
        QueryTask queryTask = new QueryTask(GetRestURL(dynMapServLayer));
    
        var result = await queryTask.ExecuteAsync(query);   
    
        // etc ....
    }
    

    Update:

    On VS2010, you can either using Async CTP or use this syntax http://msdn.microsoft.com/en-us/vstudio/hh533273.aspx 
    
       initializationTask.ContinueWith(()=> ...)
    
    It is best to try this with a test project first.
    

提交回复
热议问题