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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:07:14+00:00 2026-05-13T07:07:14+00:00

I am trying to use the .NET Reactive Framework to simplify some asynchronous calls

  • 0

I am trying to use the .NET Reactive Framework to simplify some asynchronous calls to a WCF service used by a Silverlight 3 app that I’m writing.

The trouble is that I’m having a hard time finding a way to structure my code in a way that will work. Part of the problem, no doubt, is understanding what mechanisms are available in Reactive and how to use them to solve my problem.

I’m trying to string together a series of WCF server calls – if they were synchronous, they would look something like this:

switch( CurrentVisualState )
{
    case GameVisualState.Welcome:
        m_gameState = m_Server.StartGame();
        if( m_GameState.Bankroll < Game.MinimumBet )
            NotifyPlayer( ... );  // some UI code here ...
        goto case GameVisualState.HandNotStarted;

    case GameVisualState.HandNotStarted:
    case GameVisualState.HandCompleted:
    case GameVisualState.HandSurrendered:
        UpdateUIMechanics();
        ChangeVisualState( GameVisualState.HandPlaceBet );
        break;

    case GameVisualState.HandPlaceBet:
        UpdateUIMechanics();
        // request updated game state from game server...
        m_GameState = m_Server.NextHand( m_GameState, CurrentBetAmount );
        if( CertainConditionInGameState( m_GameState ) )
            m_GameState = m_Server.CompleteHand( m_GameState );
        break;
}

The calls to m_Server.XXXX() used to be implemented directly within the Silveright app (thus they could be synchronous) – but now are implemented within a WCF service. Since Silverlight forces you to call WCF services asynchronously – rewriting this block of code has been tricky.

I was hoping to use Observable.FromEvent<>() to subscribe to the various XXXCompleted events that the WCF proxy code generates, but it’s unclear to me how to get this to work. My original attempt looked something like:

var startObs = Observable.FromEvent<StartGameCompletedEventArgs>(
                  h => m_Server.StartGameCompleted += h,
                  h => m_Server.StartGameCompleted -= h );

startObs.Subscribe( e => { m_gameState = e.EventArgs.Result.StartGameResult;
                           if( m_GameState.Bankroll < Game.MinimumBet )
                               NotifyPlayer( ... );  // some UI code here ...
                           TransitionVisual( GameVisualState.HandNotStarted );
                         } );  // above code never reached...

m_Server.StartGameAsync();  // never returns, but the WCF service is called
  • 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-13T07:07:14+00:00Added an answer on May 13, 2026 at 7:07 am

    I was able to figure out how to get this to work. I am posting this answer in the interest of sharing what I’ve learned.

    It turns out that deciding which thread to execute a subscribed observer on is very important when dealing with Silverlight WCF calls. In my case, I needed to ensure that the subscribed code runs on the UI thread – which was accomplished by the following change:

    var startObs = Observable.FromEvent<StartGameCompletedEventArgs>(
                      h => m_Server.StartGameCompleted += h,
                      h => m_Server.StartGameCompleted -= h )
            .Take(1) // necessary to ensure the observable unsubscribes
            .ObserveOnDispatcher(); // controls which thread the observer runs on
    
    startObs.Subscribe( e => { m_gameState = e.EventArgs.Result.StartGameResult;
                               if( m_GameState.Bankroll < Game.MinimumBet )
                                   NotifyPlayer( ... );  // some UI code here ...
                               TransitionVisual( GameVisualState.HandNotStarted );
                             } );  // this code now executes with access to the UI
    
    m_Server.StartGameAsync();  // initiates the call to the WCF service
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to use JSON.NET framework in a windows Form to read some information
I am trying to use Auto-implemented properties in VS2005. I have .NET 3.0 framework
I'm trying to use TestDriven.Net not only to test my code, but to call
I'm trying to use a .NET assembly from VB6 via interop without placing it
I am trying to use ASP.NET Server Controls (ASP.TextBox etc) with MVC (to take
I am trying to use the .NET Backgroundworker Object in an application I am
So, I'm trying to use ADO.NET to stream a file data stored in an
I am trying to use the ASP.NET Dynamic Data features to generate CRUD scaffolding
I am currently trying to use NAnt and CruiseControl.NET to manage various aspects of
I am trying to use log4net in an ASP.NET application with Visual Studio 2005.

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.