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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:13:26+00:00 2026-06-05T19:13:26+00:00

Every tick of timer I’d like to check the received data: 000000000 and if

  • 0

Every tick of timer I’d like to check the received data: "000000000" and if any of these bits are set to 1 then change picturebox. This part of code is working – but I think I have a memory leak problem (memory used by program is increasing drastically). How to resolve this problem?

 private void RefreshingTimerTick(object sender, EventArgs e)
 {
    for (int i = 1; i < 9; i++)
    {
       if (ReceivedDataTextBox.Text[i - 1].ToString() == "1")
          ((PictureBox)this.tabPage1.Controls["pictureBox_DO" + i.ToString()]).Image = new Bitmap(@"Logos\\green.png");
       else ((PictureBox)this.tabPage1.Controls["pictureBox_DO" + i.ToString()]).Image = new Bitmap(@"Logos\\red.png");
    }
 }
  • 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-05T19:13:27+00:00Added an answer on June 5, 2026 at 7:13 pm

    You need to dispose of the old image (this.tabPage1.Controls["pictureBox_DO" + i.ToString()]).Image) before assigning it to a new one

    private Bitmap _greenBitmap = new Bitmap(@"Logos\green.png"); 
    private Bitmap _redBitmap = new Bitmap(@"Logos\red.png");
    
    private void RefreshingTimerTick(object sender, EventArgs e)
    {
       for (int i = 1; i < 9; i++)
       {
           PictureBox p = 
              (PictureBox)this.tabPage1.Controls["pictureBox_DO" + i.ToString()];
           if(p != null && p.Image != null)
           {  
              p.Image.Dispose();
           }
    
           bool is_one = (ReceivedDataTextBox.Text[i - 1].ToString() == "1");
           if(p != null)
           {
              p.Image = (is_one) ? _greenBitmap : _redBitmap;
           }
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'd like to update field in my db every tick of timer: I know
I need to display image in openGL window. Image changes every timer tick. I've
I'm using a Threading.DispatcherTimer and every tick of the timer runs a subroutine. Is
I've got a listbox that displays data pulled from a database on every timer
I'm trying to create a timer which updates a label every tick, This is
I have a timer and on every tick I want to take an image
I Have the below Asp.net Code: the problem is that When Timer Tick Every
I want a timer tick/elapsed event inside a new thread. It seems like I
I have an application that start System.Threading.Timer, then this timer every 5 seconds read
when i using ajax control but control tick every 1 secound and when i

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.