Silverlight HttpWebRequest.Create hangs inside async block
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When HttpWebRequest.Create appears to hang in a Silverlight async flow, the real problem is often not the Create call itself. In many cases the application is blocked by the surrounding async pattern, UI-thread synchronization, or a network restriction that only becomes visible at that point in the code. Because Silverlight is a legacy client runtime with a constrained networking model, the safest fix is usually to simplify the request flow rather than layering more async wrappers on top of it.
Understand What Create Is Supposed to Do
HttpWebRequest.Create normally just constructs a request object for a URI. It does not perform the network round trip by itself. If the code looks hung on that line, there are a few common explanations:
- The debugger is stopping at the first line after a blocked earlier continuation.
- The UI thread is deadlocked by waiting on an async result.
- The runtime is resolving networking or policy information and the actual issue is environmental.
That distinction matters because it changes the debugging strategy. If object creation is not the real bottleneck, replacing Create rarely solves anything.
Avoid Blocking the UI Thread Around Async Work
One of the most common Silverlight mistakes is mixing asynchronous network operations with synchronous waits. That can deadlock the UI thread or make the code look frozen.
A problematic pattern looks like this:
If DownloadAsync tries to resume on the UI context, Result can block the very thread that the continuation needs. The safer pattern is to keep the whole call chain asynchronous.
In Silverlight-era code, even when async and await are introduced later, the core rule remains the same: do not force network calls back into synchronous flow.
Use the Request Object in a Clean Async Pattern
Silverlight networking is designed around asynchronous request and response handling. A straightforward wrapper around BeginGetResponse is more reliable than pushing request creation into arbitrary background tasks.
This keeps the object creation, network start, and completion flow in one coherent place. It is usually easier to debug than wrapping Create itself in Task.Run or another background abstraction.
Check Silverlight-Specific Network Constraints
Silverlight historically had stricter networking constraints than full desktop .NET. If the request seems stuck, validate the environment:
- Confirm the URI is valid and reachable.
- Check cross-domain policy requirements if the target is remote.
- Verify that the application is not waiting on a proxy or blocked network path.
- Make sure exceptions from the response callback are surfaced instead of swallowed.
A request that never completes is often a connectivity or policy problem that looks like an async bug because the error is not being observed properly.
Prefer Simpler APIs When Possible
If the scenario is straightforward HTTP download rather than fine-grained request control, WebClient can be easier to reason about in older Silverlight code.
That does not make every problem disappear, but it removes some ceremony and can narrow the debugging surface.
Debug the Flow, Not Just the Suspicious Line
When legacy async code looks frozen, the best debugging questions are:
- Which thread is blocked?
- Which callback or continuation never fires?
- Is the exception path being observed?
- Is the target endpoint actually reachable from the runtime?
Treating the line with HttpWebRequest.Create as the sole suspect often wastes time. In older client frameworks, the visible symptom and the actual cause are frequently separated.
Common Pitfalls
- Calling
.Resultor.Wait()on async network work and blocking the UI thread. - Wrapping
HttpWebRequest.Createin extra background-task logic instead of fixing the surrounding async flow. - Ignoring Silverlight network restrictions such as policy or endpoint reachability.
- Swallowing exceptions inside callbacks and then interpreting silence as a hang.
- Using a complex request abstraction when a simpler
WebClientflow would be easier to validate first.
Summary
- '
HttpWebRequest.Createis usually not the true source of the hang; the surrounding async pattern often is.' - Keep network code asynchronous end to end and avoid synchronous waits on the UI thread.
- Use a clean request wrapper around
BeginGetResponseif you needHttpWebRequest. - Validate network reachability and Silverlight-specific constraints before blaming the API surface.
- Simplify the flow first, then debug where the continuation or callback actually stops.
Related reading
- Simple async await tcp server design
- Simple Asynchronous Multi-Threaded HTTP request library for C
- Simple Deadlock Examples
- Simple description of worker and I/O threads in .NET
- Similar code in Tasks returning different status codes
- Simple DynamoDB request failing with ResourceNotFoundException
- Simple description of worker and I/O threads in .NET
- Simple example of threading in C
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.