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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:17:25+00:00 2026-05-18T23:17:25+00:00

I’m new to multithreading (and a somewhat beginner / intermediate programmer), and so I

  • 0

I’m new to multithreading (and a somewhat beginner / intermediate programmer), and so I may be missing something very obvious. I’m currently working on an application that has to pull data off a server (a bloomberg server to be exact) and also run business logic.

To pull data off the server, you basically have to run an endless loop to constantly refresh the data. Currently, all the data pull code / logic is in one seperate class, and has a number of public objects (dataDict in code below) that get updated with the newest data.

My thought was to run the data pull part of the program on a seperate thread, and have the rest of the business logic run on the main thread. Then, whenever the business logic required the most recent data, it could just call the data object from the other thread (a dictionary). In regards to the code below, I would like that class to run in the background and have the main business logic pick up the Dictionary, Object> dataDict when required. I’m really not sure how to best do this though.

I tried using a BackgroundWorker, but the issue that I ran into was that because the loop was endless I could never fire the RunWorkerCompleted event handler, and the DoWork handler would be called too soon (it takes some time for the data to fully download).

Any help would be much appreciated!!

To illustrate part of the program, the code for the datapull is (note, I had to do some editing so the braces/brackets may not be perfect):

class BloombergSync
{
    private Session mainSession = new Session();
    private List<String> contracts = new List<string>();
    private List<String> fields = new List<string>();
    public List<String> safeContracts = new List<string>();
    public List<String> safeFields = new List<string>();
    public Dictionary<Tuple<string, string>, Object> dataDict = new Dictionary<Tuple<string, string>, object>();
    private BackgroundWorker worker = new BackgroundWorker();


    {

        while (true)
        {

            try
            {
                Event eventObj = mainSession.NextEvent();

                foreach (Message msg in eventObj.GetMessages())
                {
                    if (eventObj.Type == Event.EventType.SUBSCRIPTION_DATA)
                    {
                        Element dataElement = msg.AsElement;

                        //Figures out which contract the data is in reference to.
                        string topic = msg.TopicName;

                        // Then must add the data to the appropriate contract and field. 
                        foreach (string field in fields)
                        {
                            if (dataElement.HasElement(field, true))
                            {
                                // Collects data for the field
                                Element elm = dataElement.GetElement(field);
                                var dataPoint = elm.GetValue();

                                // Have to figure out how to select first topic, and then the field within that topic. Has
                                // two keys (first topic, then field).
                                Tuple<string, string> tuple = new Tuple<string, string>(topic, field);
                                dataDict[tuple] = dataPoint;
                                worker.ReportProgress(1);
                            }

                        }

                     }
                    else
                    {
                        //Do Nothing if not data
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Got Exception:" + ex);
            }

        }
    }
  • 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-18T23:17:26+00:00Added an answer on May 18, 2026 at 11:17 pm

    Sounds like a producer-consumer scenario. You need a thread-safe object (in your case a queue) for transferring data.

    In .NET 4.0 there’s a System.Collections.Concurrent which is thread-safe and you can use in your project. Then you background worker can put data in CuncurrentQueue and consumer(s) can dequeue data items.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

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.