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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:54:18+00:00 2026-06-14T18:54:18+00:00

In my dll I expose an event like so: public delegate void LogMsgEventHandler(object sender,

  • 0

In my dll I expose an event like so:

 public delegate void LogMsgEventHandler(object sender, LogEventArgs e);

        public event LogMsgEventHandler newLogMessage;

        public class LogEventArgs : EventArgs
        {
            public string logMsg;
        }

        protected virtual void OnChanged(LogEventArgs e)
        {
            if (newLogMessage != null)
                newLogMessage(this, e); 
        }

The various methods fire the event to log operation details. On my main form that uses the dll I output any log msgs to a listbox:

 slotUtil.newLogMessage += new slotUtils.LogMsgEventHandler(slotUtil_newLogMessage);

..

  void slotUtil_newLogMessage(object sender, slotUtils.LogEventArgs e)
        {
            lbDebug.Items.Add(e.logMsg);
        }

The problem is if the logging event is fired too rapidly, the form freezes up. I assume this is a threading problem? How can I fix this design where the form updates fluidly? Is this a bad design? My alternate design id was too store all logging in a private string in the dll and then only dump the log when a particular method is called. Thoughts?

Thanks!

  • 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-14T18:54:19+00:00Added an answer on June 14, 2026 at 6:54 pm

    It is not a Threading issue if instances of classes from your dll aren’t in another thread. The event handler

    void slotUtil_newLogMessage(object sender, slotUtils.LogEventArgs e)
            {
                lbDebug.Items.Add(e.logMsg);
            }
    

    executes in the same thread where it is registered.

    So if your instances are in the UI thread this event handler is executing in the UI thread also. It adds new item to the ListBox which triggers new listbox redraw. If events are firing faster than the drawing occurs, then event handlers will pile up in a queue waiting for Invalidates to finish. If this is the case you should try to, at least do something like this:

    System.Windows.Forms.Timer t;
    public Form1()
    {
        InitializeComponent();
    
        t = new System.Windows.Forms.Timer();
        t.Interval = 1000;
        t.Tick += new EventHandler(t_Tick);
    }
    
    void t_Tick(object sender, EventArgs e)
    {
        for(int i = 0;i<count;i++)//you must add here only those valid strings, can't use foreach
            lbDebug.Items.Add(item);
        count = 0;
    }
    
    static int count = 0;
    static string[] items = new string[5];
    void slotUtil_newLogMessage(object sender, slotUtils.LogEventArgs e)
    {
                t.Stop();
                items[count++] = e.logMsg;
                if (count >= items.Length)
                {
                    foreach (string item in items)
                        lbDebug.Items.Add(item);
                    count = 0;
                }
                else
                {
                    t.Start();
                }
     }
    

    The adding of the items to the listbox will happen either when five logs are ready or a second has elapsed after last log. You can add whatever number of logs in the array (just change it’s size) before they are added to the listbox.

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

Sidebar

Related Questions

I want to expose some functionality of a internal object as a DLL -
I have two vc++ dll projects, which will generate two dlls. A vector<vector<string>> object
I have a dll in C# which returns a class object. DLL code: Person.cs:
How do I expose a class from a dll ? The application importing the
Suppose assembly Assembly1.dll contains 3 classes: Class C1, C2, C3. I want to expose
I have written a class dll in Net that I have to expose to
I am designing a WPF application that uses a DLL with maybe 40 public
I am creating a gui widget a dll library, a class that derives from
I'm trying to expose the attachment functionality in my c# code from MapiEx.dll using
I have a C++ DLL (no code) that I want to expose to .NET

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.