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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:42:49+00:00 2026-06-06T12:42:49+00:00

I have a small, simple C# application which updates an icon in the system

  • 0

I have a small, simple C# application which updates an icon in the system tray. I use it to graphically show the CPU usage. The application works great. I keep the Window hidden and don’t show it in the taskbar so it doesn’t get in the way.

My issue is that it will run great for a while. Often several hours. But then it will mysteriously quit. No warnings. Nothing. The icon is just gone and the program is no longer running. I have tested the program in the debugger under varying conditions, so I don’t think that is it. Is there something obvious I am missing? If the program encounters an error and quits should I be expecting a message if the Form is hidden? Is there some “keep-alive” message or something that I need to handle?

Here is the relevant section of code:

public Form1()
{
    InitializeComponent();

    trayIcon = new NotifyIcon();
    trayIcon.Text = "CPU Utilization";
    trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);

    trayIcon.Visible = true;

    update = new Thread(new ThreadStart(UpdateCPU));
    update.Start();
}

protected override void OnLoad(EventArgs e)
{
    Visible = false;
    ShowInTaskbar = false;

    base.OnLoad(e);
}

private void UpdateCPU()
{
    Bitmap bm = new Bitmap(32, 32);
    Graphics g = Graphics.FromImage(bm);

    while (true)
    {
        g.FillRectangle(new SolidBrush(c3), 17, 17, 15, 15);
        trayIcon.Icon = System.Drawing.Icon.FromHandle(bm.GetHicon());

        Thread.Sleep(1000);
    }
}

Any help would be greatly appreciated!

  • 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-06T12:42:51+00:00Added an answer on June 6, 2026 at 12:42 pm

    I would suggest you add an Unhandled Exception Handler

    Global Exception Handling for winforms control

    An Exception is likely being thrown, causing your program to exit.

    Then, introduce logging to log what the Exception was. Personally I prefer NLog.

    I’m a bit surprised that you can update trayIcon from a non-UI thread without receiving a cross-thread exception.

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

Sidebar

Related Questions

I have a simple WCF service application which contains a list of room items
I have a fairly large MVC3 application, of which I have developed a small
I have a simple solid modeling application in which I want to implement several
I'm writing a small application which exposes a simple REST-ish HTTP API. I'm stuck
I have written a small java application for which I need to obtain performance
I wish to have a small dialog based application which is passed command line
I have a small Win32 console application which is essentially a test harness. I
I have a small application which sends files over the network to an agent
I have created a small and simple android app. I tried installing it on
I have written a small makefile for a few simple C programs that compiles

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.