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 5941557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:07:37+00:00 2026-05-22T16:07:37+00:00

Let’s put aside for the moment, the question of whether synchronous-like operations should even

  • 0

Let’s put aside for the moment, the question of whether synchronous-like operations should even be attempted within the context of a Silverlight app. If I use ManualResetEvent as in the following code:

    static string result;
    static AutoResetEvent are = new AutoResetEvent(false);
    static ManualResetEvent mre = new ManualResetEvent(false);
    public static string AsyncCall()
    {
        string url = "https://stackoverflow.com/feeds/tag/silverlight";
        WebClient w = new WebClient();
        w.DownloadStringCompleted += new DownloadStringCompletedEventHandler(w_DownloadStringCompleted);
        w.DownloadStringAsync(new Uri(url), url);
        mre.WaitOne();
        return result;
    }

    static void w_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        result = e.Result;
        mre.Set();
    }

As you’d expect from reading ManualResetEvent on MSDN, “When the controlling thread completes the activity, it calls the Set method to signal that the waiting threads can proceed.”, when Set() is called in w_DownloadStringCompleted, control returns to the waiting thread that started waiting in AsyncCall. This is what happens when running this with .NET 4.0. The thread in AsyncCall gets blocked until the download completes and Set is called.

If I run the same piece of code in Silverlight 4, DownloadStringAsync will get called, yet control will never reach the w_DownloadStringCompleted callback. Once WaitOne() is called, that thread in AsyncCall just hangs there, and the thread which took off to process DownloadStringAsync never reaches the callback. The only way I’ve seen a thread reach the download callback in SL4 is if the thread from AsyncCall returns from AsyncCall. So Set() never gets called.

Why doesn’t ManualResetEvent work as expected in Silverlight 4? Why does it differ from .NET 4?
Is this maybe Microsoft’s enforcement of the asynchronous design pattern?
Or is there something I’m missing?

Thanks

  • 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-05-22T16:07:38+00:00Added an answer on May 22, 2026 at 4:07 pm

    The networking callbacks in Silverlight will always arrive in the same thread as they were originated. For example, if you make a WebClient.DownloadStringAsync on the UI thread (i.e., on a button click event), then the callback call will be queued to be delivered on the same UI thread. However, your call to mre.WaitOne() is blocking the UI thread, so the callback is never invoked, and the mre.Set() call never happens.

    So yes, that’s a kind of enforcement in the asynchronicity of networking calls – you really can’t do synchronous calls, even if they seem to be synchronous.

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

Sidebar

Related Questions

Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I can call a method like this: core::get() . What is the
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say there is a graph and some set of functions like: create-node ::
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Let's suppose I have an XML file like this: <?xml version=1.0 encoding=ISO-8859-1?> <MIDIFile> <Event>
Let I have an array like a <- seq(1, 100, 1) and I want
Let's say I've got a collection of 10 million documents that look something like

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.