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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:03:54+00:00 2026-05-23T05:03:54+00:00

Just out of personal interest, I decided to try to write a basic web

  • 0

Just out of personal interest, I decided to try to write a basic web server using Reactive Extensions (aka Rx). Almost immediately, I came up against the following problem:

HttpListener’s async pattern doesn’t match the normal async pattern signature, the EndGetContext returns a HttpListenerContext instead of an IAsyncResult!

So my question is: is there a way around this?

Here’s some code – the compiler (rightly) complains about the second argument to Observable.FromAsyncPattern:

Update – As Jon rightly pointed out, it wasn’t the pattern, it’s complaining that I haven’t provided the return type – this works:

var observable = Observable.FromAsyncPattern<HttpListenerContext>(listener.BeginGetContext, listener.EndGetContext);

The original code:

using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RxWebTest
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpListener listener = new HttpListener();
            try
            {
                listener.Start();

                var observable = Observable.FromAsyncPattern(listener.BeginGetContext, listener.EndGetContext);



                Console.ReadLine();
            }
            finally
            {
                listener.Abort();
            }
        }
    }
}
  • 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-23T05:03:55+00:00Added an answer on May 23, 2026 at 5:03 am

    That is the normal pattern. It’s BeginGetContext which returns IAsyncResult; EndGetContext takes an IAsyncResult and returns the result of the asynchronous operation – the context. That’s exactly the same as (say) Stream.BeginRead/EndRead, where EndRead returns an int, the number of bytes read.

    What happens when you try the code you’ve posted? I can’t immediately see why it wouldn’t work.

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

Sidebar

Related Questions

This question is not a homework, it is just out of personal interest and
I just started trying out a book of OpenGL out of personal interest and
This question is just out of interest, and perhaps could be useful for my
This is more out of personal curiosity/interest than a specific problem I'm trying to
I just started using eclipse for some personal projects and am finding the transition
I've decided to use SQLite for my personal development project, because it just sprung
Just as a personal experiment, in order to try to learn better about programming
I'm doing a personal, just for fun, project that is using screen scraping to
Our core server is calling out to a soap web service over https on
Just out of curiosity: I know I can tell the compiler if I want

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.