StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
CLR PerformanceCounter class scripting
Rank: Member
Groups: Approved
Joined: 4/2/2020(UTC) Posts: 11 Thanks: 4 times Was thanked: 1 time(s) in 1 post(s)
|
I was wondering if someone would be able to help me with this CLR call that seems to be failing when called from a script:
var perfCounter = clr.System.Diagnostics.PerformanceCounter("Processor","% Processor Time", "_Total"); ^^^causes invalid generic type argument exception
var perfCounter = clr.System.Diagnostics.PerformanceCounter; perfCounter.CategoryName="Processor"; perfCounter.CounterName="% Processor Time"; perfCounter.InstanceName= "_Total"; ^^^causes object has no suitable property or field named ... exception
Both these calls are documented in the system.diagnostics class.. am I missing something?
Basically what I'm trying to do is to automate an action in visual studio and save once processing is done and the only way I can know that is to check the cpu usage of the process. I can write another program to execute on action and exit when the devenv cpu usage drops but it would be nice to be able to do it all within the scripting engine
|
|
|
|
Rank: Advanced Member
Groups: Translators, Moderators, Approved Joined: 4/6/2020(UTC) Posts: 79 Thanks: 1 times Was thanked: 21 time(s) in 21 post(s)
|
|
1 user thanked liuxilu for this useful post.
|
|
|
Rank: Advanced Member
Groups: Translators, Moderators, Approved Joined: 4/6/2020(UTC) Posts: 79 Thanks: 1 times Was thanked: 21 time(s) in 21 post(s)
|
You may think of other ways, since you know the process's done not by CPU usage...
|
|
|
|
Rank: Member
Groups: Approved
Joined: 4/2/2020(UTC) Posts: 11 Thanks: 4 times Was thanked: 1 time(s) in 1 post(s)
|
Thanks for your help! Yeah, it is a bit janky. Basically this script executes the shortcut to add a function call to a code map.. waits for the visual studio process to drop to 0% cpu usage to indicate that it's done, saves the updated map, then navigates back to where I was before so I can continue adding functions. Not pretty, but for engineering code, it'll do
var pollingInterval = 500; var initialDelay = 2000;
var info = new DisplayTextInfo(); info.Title = 'Waiting for Visual Studio'; info.TitleAlignment = 'Center'; info.Message = 'Hold Left Shift to Abort'; info.MessageAlignment = 'Left'; info.Duration = pollingInterval; info.Opacity = 0.7; info.Location = 'top'; info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold)); info.MessageFont = new Font('Segoe UI Semibold', 12); info.BackColor = 'black'; info.ForeColor = 'white'; info.Padding = 15; info.UsePrimaryScreen = true;
var perfCounter = new clr.System.Diagnostics.PerformanceCounter; perfCounter.CategoryName="Process"; perfCounter.CounterName="% Processor Time"; perfCounter.InstanceName= "devenv"; perfCounter.NextValue()
//Add to code map shortcut sp.SendModifiedVKeys([vk.LCONTROL], [vk.OEM_5]); sp.SendModifiedVKeys([vk.LCONTROL], [vk.OEM_3]);
sp.CreateTimer("VSWait", initialDelay, pollingInterval, String.raw` if (sp.GetKeyState(vk.LSHIFT) == 1) { sp.DeleteTimer("VSWait"); } else { if (perfCounter.NextValue() == 0 ) { //wait for VS to return to idle sp.DeleteTimer("VSWait"); sp.RunOrActivate("devenv.exe") sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_S]); //save updated code map sp.SendModifiedVKeys([vk.LCONTROL], [vk.OEM_MINUS]); //navigate back } else { sp.DisplayText(info); } } `);
Edited by user Wednesday, April 29, 2020 3:20:13 PM(UTC)
| Reason: Not specified
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
CLR PerformanceCounter class scripting
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close