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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:12:52+00:00 2026-05-14T01:12:52+00:00

In my application, I have a ‘logging’ window, which shows all the logging, warnings,

  • 0

In my application, I have a ‘logging’ window, which shows all the logging, warnings, errors of the application.
Last year my application was still single-threaded so this worked [quite] good.

Now I am introducing multithreading. I quickly noticed that it’s not a good idea to update the logging window from different threads. Reading some articles on keeping the UI in the main thread, I made a communication buffer, in which the other threads are adding their logging messages, and from which the main thread takes the messages and shows them in the logging window (this is done in the message loop).

Now, in a part of my application, the memory usage increases dramatically, because the separate threads are generating lots of logging messages, and the main thread cannot empty the communication buffer quickly enough. After the while the memory decreases again (if the other threads have finished their work and the main thread gradually empties the communication buffer).

I solved this problem by having a maximum size on the communication buffer, but then I run into a problem in the following situation:

  • the main thread has to perform a complex action
  • the main thread takes some parts of the action and let’s separate threads execute this
  • while the seperate threads are executing their logic, the main thread processes the results from the other threads and continues with its work if the other threads are finished

Problem is that in this situation, if the other threads perform logging, there is no UI-message loop, and so the communication buffer is filled, but not emptied.

I see two solutions in solving this problem:

  • require the main thread to do regular polling of the communication buffer
  • only performing user interface logic in the main thread (no other logic)

I think the second solution seems the best, but this may not that easy to introduce in a big application (in my case it performs mathematical simulations).

Are there any other solutions or tips?
Or is one of the two proposed the best, easiest, most-pragmatic solution?

Thanks,
Patrick

  • 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-14T01:12:52+00:00Added an answer on May 14, 2026 at 1:12 am

    Let’s make some order first.

    • you may not hold UI processing for any time U would have noticed, or he will be frustrated
    • you may still perform long operations in the UI thread. this is done by means of PeakMessage loop. If you design one or more proper peakmessage loops, you do not need multithreading, unless for performance optimization.
    • you may consider MsgWaitForSingleObject() loop instead of GetMessage if you want to communicate with threads efficiently (always better than polling)

    Therefore, if you do not redesign your message loop

    • There’s no way you can perform syncronous requests from other threads
    • You may design a separate thread for the logging
    • All non-UI logic will have to be elsewhere.

    About the memory problem:

    • it is a bad design to have one thread able to allocate all memory if another thread is stuck. Such dependency is a clear recipe for a disaster.
    • If the buffer is limited, you need to decide what happens when it’s overrun. You have two options – suspend the thread or discard the message.

    UI code:

    It is possible to design logger code that would display messages with incredible speed. Such designs are complicated, rely on sophisticated caching and arranging data for fast access, viewport management and rendering only the part that corresponds to actual pixels that the user is looking at.

    For most applications it is just a gimmick, because users do not read very fast. Most of the time it is better to design a different approach to showing logs, perhaps a stateful UI to let user choose what is interesting to him at the moment. Spy++ for example, some sysinternals tools like regmon, filemon are incredibly fast in showing their own logs. You can have a look at their source code.

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

Sidebar

Related Questions

In my application I have a window which I popup with small messages on
I have a Client/Server application written Delphi. Essentially all the application is doing is
In my console application have an abstract Factory class Listener which contains code for
I have an game application I have written for Windows Mobile and I want
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
In my application I have TextBox in a FormView bound to a LinqDataSource like
In my application I have a DataGridView control that displays data for the selected
In my current application I have a form that requires the user to enter
In my application I have a Customer class and an Address class. The Customer
In my VC++ application I have an embedded browser (MSHTML). It works fine and

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.