0

My program does every few seconds:

icon.Text = message;

Often with the same message.

QUESTION: Does it make sense to only do it when message is different from last time?
In other words, can the code below ever prevent some flickering, or is it certified 100% useless?

if ( ! message.Equals(icon.Text))
{
    icon.Text = message;
}

NotifyIcon on MSDN

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
  • It does the equivalent test [internally](http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/NotifyIcon.cs,293) – Damien_The_Unbeliever Dec 04 '15 at 08:37

1 Answers1

0

No, it is not necessary, and actually wastes time for nothing, as the .NET implementation (at least version 4.6.1) does that internally:

    public string Text {
        [...]
        set {
            [...]
            if ([...] && !value.Equals(this.text)) {
                [...]
                this.text = value;
                [...]
            }
        }

Full source code: http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/NotifyIcon.cs,293
Thanks Damien_The_Unbeliever for the tip!

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373