lmalave lmalave - 1 month ago 11
C# Question

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

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

Answer

I as able to resolve my issue by using a TIMER suggested by Sabah Shariq @

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

I added a Timer to the form and then I added the following code to the timer:

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

I then added the following code to the Click Button:

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

When I click the button it starts to show the activity of the disk in the textbox and best of all, it doesn't hang my dashboard.

Regards,