使用计时器更新Notifyicon文本的内容

时间:2013-07-25 04:28:06

标签: timer refresh auto-update notifyicon trayicon

我在系统托盘应用程序的工具提示中更新文本时遇到问题。我有一个更新几个字符串的计时器,但它不会更新notifyicon文本。这是我尝试过的。

//This is in my main
    System.Timers.Timer aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Interval = 5000;
            aTimer.Enabled = true;



        }

        private static void OnTimedEvent(object sender, ElapsedEventArgs e)
        {

            ProcessIcon.GetDNS();
            ProcessIcon.GetIP();
            ProcessIcon.getMAC();
                    ProcessIcon.showALL();
                    Fixes.SetNotifyIconText(ni, ProcessIcon.showALL()); //This one will not update, the others update fine. 


        }//End part of my main

//This part is in another class for the notifyicon part.


            public void Display()
        {



            // Put the icon in the system tray and allow it react to mouse clicks.          
            ni.MouseClick += new MouseEventHandler(ni_MouseClick1);
            ni.Icon = new Icon("WhoAmI.ico");
            Fixes.SetNotifyIconText(ni, showALL());
            ni.Visible = true;




            // Attach a context menu.
            ni.ContextMenuStrip = new ContextMenus().Create();

        }

1 个答案:

答案 0 :(得分:0)

我删除了计时器,现在当用户将鼠标悬停在图标上时调用每个功能。