C# start.process powershell longer runtime than native ps1 -


i'm using following c# code run powershell script, script runs within second when run outside of c# within following c# code block runs in excess of 9 secs. c# code compiled , run windows service under same user account (tested outputting whoami in powershell script.)

string csv = jobpath + requesttype[2] + ".csv"; string id = "123321"; var scriptfile = @"c:\jobrunner\jobrunner.ps1"; processstartinfo startinfo = new processstartinfo(); startinfo.filename = @"powershell.exe"; startinfo.arguments = @"" + scriptfile + " '" + csv + "' " + " '" + id +     "'"; startinfo.redirectstandardoutput = false; startinfo.redirectstandarderror = false; startinfo.useshellexecute = false; startinfo.createnowindow = true; process process = new process(); process.startinfo = startinfo; process.start(); 

the powershell script loads functions folder such:

$date = get-date "start $date" >> c:\temp\_log.log $psdir="c:\jobrunner\functions"   # load 'autoload' scripts get-childitem "${psdir}\*.ps1" | %{.$_}  $date = get-date  "end $date" >> c:\temp\_log.log 

can point me in direction why script slow when executed within c#?

results: (first run native second c#)

start 03/28/2015 16:05:13 - end 03/28/2015 16:05:13   start 03/28/2015 16:05:32- end 03/28/2015 16:05:41 

performance got allot better when using:

startinfo.filename = @"c:\windows\system32\windowspowershell\v1.0\powershell.exe"; 

i noticed spawned powershell.exe had *32 first tried c:\windows\syswow64\windowspowershell\v1.0 32 bit , powershell.exe in system32 64bit?

now difference is: 0.5 secs vs 1.1 secs

any further performance boosters appreciated


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -