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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:51:07+00:00 2026-06-16T17:51:07+00:00

Since I can’t find any control to use as a LED indicator on my

  • 0

Since I can’t find any control to use as a LED indicator on my winform for my serial communication transmit and receive, I created my own user-defined indicator from label. It basically sets and resets the color of a label from black to lime for receive and black to red for transmit repeatedly. Its class is as follows. However, my .NET program seem to run for couple of hours and crash completely. When I view the details for crash error, windows reports it as clr20r3 error. I’ve had a similar issue when I wrote and developed a program under fedora linux. My serial communication indicator on a form somehow caused memory leak and crashed the program and when it was removed it worked flawlessly.

So, can you have memory leak from setting and resetting backcolor of a label repeatedly within seconds?

namespace SerialLED;

interface

uses
  System.Collections.Generic,
  System.Windows.Forms,
  System.Drawing.*,
  System.Text;

type

  TheLED = public class(Label)
  private
  protected
  public
    constructor;
  end;

  TSerialIndicator = public class
  private
    method TxTimerEvent(Sender:System.Object; e:System.EventArgs);
    method RxTimerEvent(Sender:System.Object; e:System.EventArgs);
  public
    Txlight:TheLED;
    Rxlight:TheLED;
    TxTimer:System.Timers.Timer;
    RxTimer:System.Timers.Timer;
    constructor(mform:Form);
    method Transmit;
    method Receive;
  end;

implementation

method TSerialIndicator.Transmit;
begin
  TxLight.BackColor := Color.Red;
  if TxTimer.Enabled = false then
     TxTimer.Enabled:=true;
end;

method TSerialIndicator.Receive;
begin
  RxLight.BackColor := Color.Lime;

  if RxTimer.Enabled=false then
    RxTimer.Enabled:=true;
end;

method TSerialIndicator.RxTimerEvent(Sender:System.Object; e:System.EventArgs);
begin
    RxLight.BackColor := Color.Black;
    RxTimer.Enabled:=false;
end;

method TSerialIndicator.TxTimerEvent(Sender:System.Object; e:System.EventArgs);
begin
    TxLight.BackColor := Color.Black;
    TxTimer.Enabled:=false;
end;

constructor TSerialIndicator(mform:Form);
begin
    RxLight := new TheLED;
    TxLight := new TheLED;

    TxLight.AutoSize := false;
    RxLight.AutoSize := false;

    TxLight.BorderStyle := BorderStyle.Fixed3D;
    RxLight.BorderStyle := BorderStyle.Fixed3D;

    TxLight.Location := new point(52,163);
    RxLight.Location := new point(82,163);

    TxLight.Width := 20;
    TxLight.Height := 20;
    RxLight.Width :=20;
    RxLight.Height := 20;

    mform.Controls.Add(RxLight);
    mform.Controls.Add(TxLight);

    RxTimer := new System.Timers.Timer;
    TxTimer := new System.Timers.Timer;
    RxTimer.Interval:=50;
    TxTimer.Interval:=50;
    RxTimer.Enabled:=false;
    TxTimer.Enabled:=false;
    RxTimer.Elapsed += new System.Timers.ElapsedEventHandler(@RxTimerEvent);
    TxTimer.Elapsed += new System.Timers.ElapsedEventHandler(@TxTimerEvent);

    RxLight.BackColor := Color.Black;
    TxLight.BackColor := Color.Black;
end;

constructor TheLED;
begin
  self.DoubleBuffered:=true;
end;

This is how it looks on a winform:
enter image description here

  • 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-16T17:51:08+00:00Added an answer on June 16, 2026 at 5:51 pm

    Since no one wants to answer and I have solved my issue, I will answer this question myself.

    Yes, it can lead to memory leak from what I have experienced and it depends how you set the backcolor for your control. If your control is not placed on the winform, then setting and resetting backcolor within short amount of time can lead to memory leak as Hans Passant has said. So, I followed his advice.

    Basically I placed my control right on the winform and from my thread, I set and reset the backcolor. So far it has worked. I have been running my program for the last 5 days nonstop and it hasn’t crashed or lost control.

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

Sidebar

Related Questions

This is a silly question since I can't find the right keywords to use
Since I can't seem to find any documentation on this subject, is it possible
Since I migrated to Snow Leopard I can't run any Rake command from the
Since I can't make any comments (only post an answer) to this post ,
I'm getting a little bit frustrated since I can't find out which variables I
I've just started using Eclipse for Python development since we can make use of
I don't want to use *args or **kwargs since I can't change function declaration.
It is often hard to find the origin of a NaN, since it can
Since I can't find a chuffing job, I've been reading up on ReST and
since i can't find much documentation on HQL, what I often do it look

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.