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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:25:33+00:00 2026-06-11T03:25:33+00:00

I have a problem getting my observers working properly when on specific threads. Subject<bool>

  • 0

I have a problem getting my observers working properly when on specific threads.

Subject<bool> subjEvent = new Subject<bool>();
Subject<int> subjValue = new Subject<int>();

IScheduler sched = new EventLoopScheduler(ts => new Thread(ts));

subjEvent.ObserveOn(sched).Subscribe(
    r =>
        {
            if(r)
            {
                Console.WriteLine("Connected On: \t{0}", Thread.CurrentThread.ManagedThreadId);

                subjValue.ObserveOn(sched).Subscribe(
                    x => Console.WriteLine("Recieved On: \t{0}", Thread.CurrentThread.ManagedThreadId));
            }else{
                Console.WriteLine("Disconnect On: \t{0}", Thread.CurrentThread.ManagedThreadId);
            }
        }
    );

subjEvent.OnNext(true);
for(int i=0; i< 10; i++)
{
    subjValue.OnNext(i);
}
subjEvent.OnNext(false);
subjValue.OnCompleted();
subjEvent.OnCompleted();

The idea is to subscribe to something when it becomes available and unsubscribe/resubscribe with events thereafter. Now as I require to observe on a specific (read same) thread, as well as ensure correct ordering, I have an EventLoopScheduler.

The problem is I get nothing from the value subscription.

Now, if I add a Thread.Sleep(10) to the generation loop (after OnNext) it works perfectly fine. So I’m kinda perplexed as to what I’m doing wrong and would be very grateful for help/advise.

  • 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-06-11T03:25:34+00:00Added an answer on June 11, 2026 at 3:25 am

    Although this doesn’t help answer your question directly – I think Asti has done a fine job of doing that – I thought I’d post this code to help you write your queries.

    You should try very hard not to subscribe to your observables until you absolutely have to. And when you do the code in your OnNext handler needs to be as small as possible.

    Try this version of your queries:

    var query =
        from b in subjEvent.Do(x =>
            Console.WriteLine("{0}onnected On: \t{1}",
                x ? "C" : "Disc",
                Thread.CurrentThread.ManagedThreadId))
        select b ? subjValue : Observable.Empty<int>();
    
    query.Switch().Subscribe(x =>
        Console.WriteLine("Recieved On: \t{0}",
            Thread.CurrentThread.ManagedThreadId));
    

    Barring the issue with the event loop scheduler this code does the same as yours, but it only has one subscribe and it does a minimal amout of work in that subscription. I hope this helps.

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

Sidebar

Related Questions

I have a problem getting password_Reset_confirm bit working. url: (r'^password_reset/$', 'django.contrib.auth.views.password_reset'), (r'^password_reset_done/$', 'django.contrib.auth.views.password_reset_done'), (r'^password_reset_confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
I seem to have problem getting linked servers working to query between database/servers running
i am new to ios development.. i have problem in getting arrays from complex
I have problem with getting sessionID with JSON. JSON is always returning new sessionID
I just started a graphical C++ course and I have problem getting an overview
I have a problem getting the right Price for a product based on Effectivity
I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the
I have a problem getting a private method using reflection. Even with BindingFlags.NonPublic and
I have this problem getting my newly created php project on Netbeans work on
I'm using jqGrid and I have a problem getting Dynamic Linq to work. I

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.