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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:43:27+00:00 2026-05-11T09:43:27+00:00

I have just written my own logging framework (very lightweight, no need for a

  • 0

I have just written my own logging framework (very lightweight, no need for a big logging framework). It consists of an interface ILogger and a number of classes implementing that interface. The one I have a question about is TGUILogger which takes a TStrings as the logging target and synchronizes the logging with the main thread so that the Items member of a listbox can be used as the target.

type   ILogger = Interface (IInterface)     procedure Log (const LogString : String; LogLevel : TLogLevel);     procedure SetLoggingLevel (LogLevel : TLogLevel);   end;  type       TGUILogger = class (TInterfacedObject, ILogger)   public     constructor Create (Target : TStrings);     procedure Log (const LogString : String; LogLevel : TLogLevel);     procedure SetLoggingLevel (LogLevel : TLogLevel);   private     procedure PerformLogging;   end;  procedure TGUILogger.Log (const LogString : String; LogLevel : TLogLevel); begin   TMonitor.Enter (Self);   try     FLogString := GetDateTimeString + ' ' + LogString;     TThread.Synchronize (TThread.CurrentThread, PerformLogging);   finally     TMonitor.Exit (Self);   end; end;  procedure TGUILogger.PerformLogging; begin   FTarget.Add (FLogString); end; 

The logging works, but the application does not close properly. It seems to hang in the Classes unit. The stack trace:

System.Halt0, System.FinalizeUnits, Classes.Finalization, Classes.FreeExternalThreads, System.TObject.Free, Classes.TThread.Destroy, Classes.TThread.RemoveQueuedEvents

What am I doing wrong here?

EDIT: I just found the following hint in the Delphi help for TThread.StaticSynchronize

Warning: Do not call StaticSynchronize from within the main thread. This can cause  an infinite loop.      

This could be exactly my problem since some logging request come from the main thread. How can I solve this?

  • 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. 2026-05-11T09:43:28+00:00Added an answer on May 11, 2026 at 9:43 am

    If you don’t find any simpler way, you could try doing this:

    At program initialization, (from the main thread,) have your logging subsystem call the Windows API function GetCurrentThreadID and store the result in a variable. (EDIT: the MainThreadID variable in the System unit, gets initialized this way automatically for you at startup. Thanks, mghie.) When a logging request comes in after that, call GetCurrentThreadID again, and only synchronize if it’s coming from a different thread.

    There are other tricks that don’t involve the Windows API, but they end up being more complicated, especially if you have a bunch of different custom TThread descendants. The basic principle is the same, though: Verify whether or not you’re in the main thread before you decide whether or not to call StaticSynchronize.

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

Sidebar

Related Questions

Hey gang. I have just written a client and server in C++ using sys/socket.
I have just been re-working an old bit of compiler-like code written using bison.
I have written a following code to get just the file name without extension
I have written a SQL query that works just fine, but am having a
I have written a function that positions a tooltip just above a textbox. The
I have written a Perl script, I just want to give it to every
Just wondering what little scripts/programs people here have written that helps one with his
I have a neural network written in Erlang, and I just bought a GeForce
I have the source code of an application written in C++ and I just
I have always written regexes like this <A HREF=([^]*) TARGET=_blank>([^<]*)</A> but I just learned

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.