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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:48:54+00:00 2026-05-27T19:48:54+00:00

This is the model for 3 layer application with asynchronous response I am trying

  • 0

This is the model for 3 layer application with asynchronous response I am trying to use:

  • GUI
  • Back-end
  • Remote Server

GUI:

private async void readFloatButton_Click(object sender, RoutedEventArgs e)
{
  FloatValueLabel.Content = (await srvProtocol.ReadFloat("ReadFloatX")).ToString();
}

Back-end (uses internal variables binReader and connection)

public Task<float> ReadFloat(string cmd)
 {
   var tcs1 = new TaskCompletionSource<float>();
   var floatTask = tcs1.Task;    
   RegisterResponse(cmd, 
                     () =>
                     tcs1.SetResult(_binReader.ReadSingle());
                    );
   // We are ready: now send request to server(assuming that this is a quick operation)
   connection.Send(cmd); 
   return floatTask;
 }

Here RegisterResponse adds a < Key, Action > pair to some thread-safe dictionary.
Another worker thread reads from the network stream messages (message headers) and calls actions according to the string cmd found in the message header.

Now the question:

  • is it possible to reach same level of conciseness when I will need to subscribe GUI elements for periodic updates (not a single callback)?
  • 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-27T19:48:55+00:00Added an answer on May 27, 2026 at 7:48 pm

    Well, you could just take what you have and put in into a loop, e.g.:

    private async void StartReading()
    {
      while (true)
      {
        FloatValueLabel.Content = (await srvProtocol.ReadFloat("ReadFloatX")).ToString();
        await Task.Delay(1000);
      }
    }
    

    Though I personally am not fond of the “infinite async” loop. The only way to stop the loop is to throw an exception (error or cancellation).

    The Rx library is more suited for subscriptions. It allows a high level of
    “conciseness,” but has a steeper learning curve.

    You can also wrap all the subscription logic into a Model/ViewModel. This particularly makes sense when dealing with “updating” the same conceptual value. In that case, StartReading would be a method on your Model/ViewModel. It would use async (for the infinite async loop) or ObserveOn (for Rx) to bring the updates onto the UI thread, and then use the standard INotifyPropertyChanged / ObservableCollection to update the UI indirectly.

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

Sidebar

Related Questions

class Followup < ActiveRecord::Base belongs_to :post belongs_to :comment end This model needs to only
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I'm trying to get to light. In DDD approach we have Presentation Layer(UI), Application
This model is simplified, only used for demonstration. In my application got: Data public
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
Let's say I have this model named Product with a field named brand .
I have a model that holds user address. This model has to have first_name
There are a few windows service projects in our codebase that follow this model,
I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public
I'm following this MVC model: http://java.sun.com/developer/technicalArticles/javase/mvc/ In my model I have an ArrayList shapes

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.