Disk Activity Remote Computer - Display activity changes in textbox with -Continuous

时间:2016-10-09 15:57:41

标签: c# winforms visual-studio

I am developing a dashboard to view a remote computers data (Eventviewer, Files in a directory, running Tasks, etc...). All of these are working and being display with no problems on the Dashboard.

The issue I have is when I click a Command button it runs the code shown below and it displays the Disk activity for the logical disk C: of a remote computer in the textbox txtDiskActivity.Text on the dashboard but only one line is shown (view Image).

Disk Activity Display

txtDiskActivity.Text = RunScript("Get-WmiObject -computername LT-WIN1064 -NameSpace root\\CIMV2 -Class Win32_PerfRawData_PerfDisk_LogicalDisk | where name -eq C: | select AvgDisksecPerWrite, name");

What I am trying to do is to keep this code running so it can keep showing the disk activity changes for the LogicalDisk until I exit out of the dashboard.

I have tried using -Continuous and -SampleInterval 2 -MaxSamples 10 but I cant get it to work.

One condition is that I will need to be able to use the other controls on dashboard while this code this is running.

Any suggestion?

Regards

1 个答案:

答案 0 :(得分:0)

我可以使用Sabah Shariq @

建议的 TIMER 来解决我的问题

Get Disk Counter Write activity code for remote computer and keep it refreshing.

我在表单中添加了一个Timer,然后将以下代码添加到计时器中:

txtDiskActivity.Text = FunctionCall("Get-WmiObject -computername LT-WIN1064 -NameSpace root\\CIMV2 -Class Win32_PerfRawData_PerfDisk_LogicalDisk | where name -eq C: | select AvgDisksecPerWrite, name");

然后我将以下代码添加到Click按钮:

 tmrDiskActivity.Interval = 1000;
 tmrDiskActivity.Start();

当我点击按钮时,它开始在文本框中显示磁盘的活动,最重要的是,它不会挂起我的仪表板。

此致