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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:56:55+00:00 2026-06-14T03:56:55+00:00

Within a user-defined class, I have a timer and it just won’t start when

  • 0

Within a user-defined class, I have a timer and it just won’t start when I Timer.Enabled.

User-Defined Class:

  TSerialIndicator = public class
  private
    method TxTimerEvent(Sender:System.Object; e:System.EventArgs);
  public    
    Txlight:Label;
    Txtimer:System.Windows.Forms.Timer;
    constructor(mform:Form);
    method Transmit;
    method Receive;
  end;

Here is the constructor:

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

    TxLight.AutoSize := false;

    TxLight.BorderStyle := BorderStyle.FixedSingle;

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

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

    mform.Controls.Add(TxLight);

    TxTimer := new System.Windows.Forms.Timer;
    TxTimer.Interval:=1;

    TxTimer.Enabled:=false;
    TxTimer.Tick += new System.EventHandler(@TxTimerEvent);

    TxLight.BackColor := Color.Black;
end;

Here is Transmit method as defined:

method TSerialIndicator.Transmit;
begin
  TxLight.BackColor := Color.Red;

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

Here is TxTimerEvent as defined:

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

Here is how it is created and used:

Slight := new TSerialIndicator(self);
Slight.Transmit;

When I call Transmit from some other part of the program, it does its thing, but TxTimerEvent won’t fire at all ever. I even tried Start/Stop its methods. It still didn’t execute its Tick Event. However, I did notice that when I do enable the timer from within the constructor it does fire TxTimerEvent ONCE.

What am I doing wrong?

Thanks in advance,

  • 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-14T03:56:56+00:00Added an answer on June 14, 2026 at 3:56 am

    With method names like “Transmit” and “Receive”, it is likely that a thread is involved. Like the threadpool thread on which a SerialPort’s DataReceived event runs. Or code that runs due to a System.Timers.Timer’s Elapsed event. Etcetera.

    Setting a System.Windows.Forms.Timer’s Enabled property to true in a worker thread like that doesn’t work, it is not a thread-safe class. It does what it normally does, creates a hidden window that uses Windows’ SetTimer() method to get the Tick event to fire. But that window is created on a thread that doesn’t pump a message loop. So Windows doesn’t generate the WM_TIMER messages.

    Use Control.Begin/Invoke() as necessary to ensure any code that’s related to timers or controls runs on the UI thread.

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

Sidebar

Related Questions

Are there known issues with storing user defined types within index organized tables in
I have the following user control that is embedded within another user control. <UserControl.Resources>
I wanted to overload an operator in a class , and have it private
I have a Rails controller where I accidentally defined the 'edit' method inside the
I have the following packages: spark      spark.engine Within spark I have a class
Let's say I have some classes defined as follows: class Security { Boolean AuthenticateUser(String
I'm looking for a way to find/replace links to images (within user-generated content) without
The following code will search for the user within the domain controller, but I
I use AVAudioPlayer to play an mp3 file to a user within my iPhone
I wonder if it's possible to load jQuery within Opera User JavaScript , so

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.