0

I am working on something like Task Manager. I have UserControl with async method added to Initialized event that once every second gets all required data from system.

private async void UserControl_Initialized(object sender, EventArgs e)
        {
            try
            {
                await Task.Run(() =>
                {
                    while (true)
                    {

                        string cpuU = this.CpuUsage;
                        string cpuC = this.CpuClock;
                        string cpuPC = this.CpuProcesses;
                        string cpuTC = this.CpuThreads;
                        string memU = this.MemUsage;
                        string memA = this.MemAvailable;
                        string memC = this.MemCached;
                        Dispatcher.Invoke(() => {

                            this.usageBlock.Text = cpuU;
                            this.frequencyBlock.Text = cpuC;
                            this.processesBlock.Text = cpuPC;
                            this.threadsBlock.Text = cpuTC;
                            this.ramUsageBlock.Text = memU;
                            this.ramAvailableBlock.Text = memA;
                            this.ramCachedBlock.Text = memC;
                            });
                        Thread.Sleep(1000);
                    }
                });
            }
            catch(Exception ee)
            {
                Debug.WriteLine(ee.Message);
            }
        }

All of this works perfectly. The problem is that the project runs even when i didn't start debug. Video

I suppose Visual Studio somehow triggers Initialize event for designer to work. How to prevent this strange behavior and stop the rise of the machines?

Cregennan
  • 1
  • 1
  • 1
    What do you mean "the project already runs even before debug starts"? How does the information in your screenshot even indicate this is what's happening? Are you talking about the designer on the left? In the screenshot you provided the program is not running (unless you opened it outside of Visual Studio) – Jesse Oct 17 '22 at 22:51
  • @Jesse Here is link to video: https://imgur.com/a/JJyDQOq. – Cregennan Oct 17 '22 at 23:00

0 Answers0