Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:12:48+00:00 2026-06-08T18:12:48+00:00

I have a silverlight 5 app that depends on several asynchronous calls to web

  • 0

I have a silverlight 5 app that depends on several asynchronous calls to web services to populate the attributes of newly created graphics. I am trying to find a way to handle those asynchronous calls synchronously. I have tried the suggestions listed in this article and this one. i have tried the many suggestions regarding the Dispatcher object. None have worked well, so I am clearly missing something…

Here is what I have:

public partial class MainPage : UserControl {

 AutoResetEvent waitHandle = new AutoResetEvent(false);

 private void AssignNewAttributeValuesToSplitPolygons(List<Graphic> splitGraphics)
 {
   for (int i = 0; i < splitGraphics.Count; i++) 
   {
       Graphic g = splitGraphics[i];

       Thread lookupThread1 = new Thread(new ParameterizedThreadStart(SetStateCountyUtm));
       lookupThread1.Start(g);
       waitHandle.WaitOne();

       Thread lookupThread2 = new Thread(new ParameterizedThreadStart(SetCongressionalDistrict));
       lookupThread1.Start(g);
       waitHandle.WaitOne();
 }

 private void SetStateCountyUtm(object  graphic)
 {
    this.Dispatcher.BeginInvoke(delegate() {
            WrapperSetStateCountyUtm((Graphic)graphic);
     });
 }

 private void WrapperSetStateCountyUtm(Graphic graphic)
    {
        GISQueryEngine gisQEngine = new GISQueryEngine();
        gisQEngine.StateCountyUtmLookupCompletedEvent += new GISQueryEngine.StateCountyUtmLookupEventHandler(gisQEngine_StateCountyUtmLookupCompletedEvent);
        gisQEngine.PerformStateCountyUtmQuery(graphic.Geometry, graphic.Attributes["clu_number"].ToString());
    }

 void gisQEngine_StateCountyUtmLookupCompletedEvent(object sender, StateCountyUtmLookupCompleted stateCountyUtmLookupEventArgs)
 {
     string fred = stateCountyUtmLookupEventArgs.
     waitHandle.Set();
 }     

}

public class GISQueryEngine
{
  public void PerformStateCountyUtmQuery(Geometry inSpatialQueryGeometry, string cluNumber)
    {
        QueryTask queryTask = new QueryTask(stateandCountyServiceURL);
        queryTask.ExecuteCompleted += new EventHandler<QueryEventArgs>(queryTask_StateCountyLookupExecuteCompleted);
        queryTask.Failed += new EventHandler<TaskFailedEventArgs>(queryTask_StateCountyLookupFailed);
        Query spatialQueryParam = new ESRI.ArcGIS.Client.Tasks.Query();
        spatialQueryParam.OutFields.AddRange(new string[] { "*" });
        spatialQueryParam.ReturnGeometry = false;

        spatialQueryParam.Geometry = inSpatialQueryGeometry;
        spatialQueryParam.SpatialRelationship = SpatialRelationship.esriSpatialRelIntersects;
        spatialQueryParam.OutSpatialReference = inSpatialQueryGeometry.SpatialReference;

        queryTask.ExecuteAsync(spatialQueryParam, cluNumber);
    }

  //and a whole bunch of other stuff i can add if needed
}

If I leave the ‘waitHandle.WaitOne()’ method uncommented, no code beyond that method is ever called, at least that I can see with the step through debugger. The application just hangs.

If I comment out the ‘waitHandle.WaitOne()’, everything runs just fine – except asynchronously. In other words, when the app reads the Attribute values of the new graphics, those values may or may not be set depending on how quickly the asynch methods return.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:12:49+00:00Added an answer on June 8, 2026 at 6:12 pm

    It’s going to be rather difficult to work through a problem like this as there are a few issues you’ll need to address. SL is by nature asynch so forcing it to try and work synchronously is usually a very bad idea. You shouldn’t do it unless it’s absolutely necessary.

    Is there a reason that you cannot wait for an async. callback? From what I see you appear to be making two calls for every state that is being rendered. I’m guessing the concern is that one call must complete before the second is made? In scenarios like this, I would kick off the first async call, and in it’s response kick off the second call passing along the result you’ll want to use from the first call. The second call response updates the provided references.

    However, in cases where you’ve got a significant number of states to update, this results in a rather chatty, and difficult to debug set of calls. I’d really be looking at creating a service call that can accept a set of state references and pass back a data structure set for the values to be updated all in one hit. (or at least grouping them up to one call per state if the batch will be too time consuming and you want to render/interact with visual elements as they load up.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight app that makes multiple (often concurrent) asynchronous calls to an
I have a WCF web-service and a Silverlight app displaying data from that service.
I have created a class that inherits for DomainService and have a Silverlight app
I have created a silverlight app that consits of like buttons within specific usercontrols
Basically I have a silverlight web App that resides within an IFrame. and that
I'm writing a silverlight app that queries a web service to populate a tree
I have a silverlight app that will be installed OOB with full trust and
I have a Silverlight app that has to load an image dynamically, depending on
In my Silverlight app I have an event handler that dynamically creates a new
I have a Windows Phone 7.5/Silverlight app. I have some code that I duplicate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.