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

The Archive Base Latest Questions

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

I have a winform application, and an observable set up like this: Form form

  • 0

I have a winform application, and an observable set up like this:

Form form = new Form();
Label lb = new Label();
form.Controls.Add(lb);

Observable.Interval(TimeSpan.FromSeconds(1))
          .Subscribe(l => lb.Text = l.ToString());

Application.Run(form);

This doesn’t work, since the l => lb.Text = l.ToString() will not be run on the main thread which created the form, but I cannot figure out how to make it run on this thread. I assume, that I should use IObservable.SubscribeOn which takes either an IScheduler or a SynchronizationContext, but I don’t know how to get the synchronizationcontext of the main thread, and the only Schedulers I could find were the static properties of Scheduler, such as Scheduler.CurrentThread, Immediate, NewThread, TaskPool and ThreadPool, none of which worked.

My Rx version is 1.0.10621.

  • 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-25T16:53:42+00:00Added an answer on May 25, 2026 at 4:53 pm

    Just after I post the question, I find the solution:

    Form form = new Form();
    Label lb = new Label();
    form.Controls.Add(lb);
    
    Observable.Interval(TimeSpan.FromSeconds(2))
              .ObserveOn(SynchronizationContext.Current)
              .Subscribe(l => lb.Text = l.ToString());
    
    Application.Run(form);
    

    This link was helpful. Two notes:

    • Not all threads have a synchronization context, but the first form that gets created on a thread will set a synchronization context for that thread, so the UI thread always has one.
    • The correct method is ObserveOn, not SubscribeOn. At the moment, I don’t know enough about this to know why, so any links in the comments would be appreciated.

    edit: Thanks to the first part of this link, I now understand more about the difference between ObserveOn and SubscribeOn. In short:

    • An observable, which observes on a synchronization context will call the IObserver methods (OnNext and friends) from that context. In my example, I observe on the main/UI thread, so therefore I get no cross thread exceptions
    • SubscribeOn is a little more complicated, so here is an example: Concat takes a number of observables and combines them to one long observable. Once an observable calls OnCompleted, the combined observable will dispose of that subscription, and subscribe to the next observable. This all happens on the thread that called OnCompleted, but there can be some problems with subscribing to observables, that were created by Observable.FromEvent, e.g. Silverlight will throw if you add an event handler from another thread than the UI thread, and WinForms and WPF will throw if you add a event handlers from multiple different threads. SubscribeOn will let you control the thread on which your observable hooks up to the underlying event.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have winform application written in c#. I would like this application to only
I have a winform application that goes with name myForm . Within this form
I have a winform application (one form), on this form there is a RichTextBox.
I have an application (winform exe) that I run several times. Does this mean
I'd like to show an input modal in my WinForm application. I have looked
I following this article for sending SMS it is a winform application.. I have
I have a winform application in c#. the main form is usually minimized. When
I have a winform application and this winform application has created few files. I
I have c# winform application and one WPF user control. How i can add
I have a WinForm application. On the main form there are a number of

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.