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

  • SEARCH
  • Home
  • 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 6555235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:47:41+00:00 2026-05-25T12:47:41+00:00

I am trying to port an engine into C# WP7 silverlight, along with its

  • 0

I am trying to port an engine into C# WP7 silverlight, along with its unit tests. Because it uses http requests, it needs to be asynchronous as dictated by the framework. The Android version of the engine I am porting uses synchronous blocking sockets on a worker thread. It invokes a callback whenever the entire operation is complete (not just the http request).

Question – how can I wrap the callback mechanism so that it does an asynch callback that can be used in an [Asynchronous] unit test?

I want it to do something like this:

using System;
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;

[TestClass]
public class WebRequestsTests : WorkItemTest
{
    [TestMethod, Asynchronous]
    public void TestWebRequest()
    {
        var webRequest = WebRequest.CreateHttp("http://www.stackoverflow.com");

        webRequest.BeginGetResponse(result =>
        {
            EnqueueCallback(() =>
            {
                WebResponse response = webRequest.EndGetResponse(result);

                // process response 

                TestComplete(); // async test complete 
            });
        }, null);
    }
} 

Do I need to implement the IAsync interface or something similar?

I’d like to have it do something like this:

using System;
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;

[TestClass]
public class WebRequestsTests : WorkItemTest
{
    [TestMethod, Asynchronous]
    public void TestWebRequest()
    {
        MyThread thread = new MyThread();

        thread.Start(result =>
        {
            EnqueueCallback(() =>
            {
                WebResponse response = thread.EndGetResult(result);

                // process response 

                TestComplete(); // async test complete 
            });
        }, null);
    }
} 

Not sure I’m also 100% comfortable with the lambda expressions either, so if those are removed, even better! 😉

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-25T12:47:42+00:00Added an answer on May 25, 2026 at 12:47 pm

    You don’t need to create a new thread to deal with the EndRequest or EndResponse callback – these will be called for you on a background thread from the ThreadPool. So something like your first code example should work.

    If you don’t like the nested lambdas just declare named methods :). You can pass state information in the Begin… methods which you can retrieve in the result object.

    What you’re asking is kind of weird – you’re wrapping an async framework with sync version, and rewrapping that with an async version. It sounds like you’re creating extra work for yourself in order to stay faithful to your port. You will also use some extra memory to keep an extra thread alive doing nothing (1MB for the stack at least).

    If you still want to do it check out this link though.

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

Sidebar

Related Questions

I'm trying to port some functionality from my engine from c++ to C#. I
Im trying to port this function to c# http://www.phpsnaps.com/snaps/view/clean-url/ I have problems to transform
I am trying to port a project (from linux) that uses Semaphores to Mac
I'm trying to use .Net serialport methods from another program which uses Unity3D engine.
Right now, I'm trying to port a Direct3D renderer from my engine. I'm and
I'm trying to port some assembly code written in Visual Studio into GNU inline
I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console
I'm trying to port an application to Mono, however Mono doesn't support Application Settings.
i'm trying to port some Java stuff to C#. I'm just wondering if the
I'm trying to port a PHP site developed by another coder (who is no

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.