0

I have question. I've got one ReverseGeocodeQuery which'll provide me details about my GPS location. Now I want to synchronize few ReverseGeocodeQuerys (each one for other GPS location). But when I just start all Query in one moment they won't execute...

Is there simple way to synchronize that Querys?

for(int i = 0; i<mySimulation.Count(); i++)
                {

                    if (i==0)
                    {
                        AddMapLayer(mySimulation.ElementAt(i).Coordinate, Colors.Yellow, false);

                        myReverseGeocodeQuery_1 = new ReverseGeocodeQuery();
                        myReverseGeocodeQuery_1.GeoCoordinate = mySimulation.ElementAt(i).Coordinate;
                        myReverseGeocodeQuery_1.QueryCompleted += ReverseGeocodeQuery_QueryCompleted_1;
                        myReverseGeocodeQuery_1.QueryAsync();
                    }

                    if (i == 1)
                    {
                        AddMapLayer(mySimulation.ElementAt(i).Coordinate, Colors.Orange, false);

                        myReverseGeocodeQuery_2 = new ReverseGeocodeQuery();
                        myReverseGeocodeQuery_2.GeoCoordinate = mySimulation.ElementAt(i).Coordinate;
                        myReverseGeocodeQuery_2.QueryCompleted += ReverseGeocodeQuery_QueryCompleted_2;
                        myReverseGeocodeQuery_2.QueryAsync();
4

1 回答 1

0

您可以使用AutoResetEvent

AutoResetEvent done = new AutoResetEvent(true);
...
for(int i = 0; i<mySimulation.Count(); i++)
{
    // Is somebody working?
    // If so I wait...
    done.WaitOne();

    if (i==0)
    {
        ....
        myReverseGeocodeQuery_1.QueryCompleted += ReverseGeocodeQuery_QueryCompleted_1;
        done.Reset(); // Hey I'm working, wait!
        myReverseGeocodeQuery_1.QueryAsync();
    }
    ...
}
...
void ReverseGeocodeQuery_QueryCompleted_1(...)
{
    ...
    done.Set(); // I'm done! Your turn...
}

当任何地理查询正在运行时,主线程应该应该和不会因为时间较晚)在WaitOne上被阻塞,避免同时启动另一个......

于 2013-06-10T23:08:11.737 回答