我的应用程序生成了一个excel表格。我想在CPU利用率为零时杀死excel表格。我用下面的代码。
在保存IIS中存在的相同Web cofig文件后,代码才能工作。 几个小时后,我必须再次保存相同的web.config 执行Excel启动和终止过程。
Dim pListOfProcesses() As Process
Dim pExcelProcess As System.Diagnostics.Process
pListOfProcesses = Process.GetProcesses
For Each pExcelProcess In pListOfProcesses
If pExcelProcess.ProcessName.ToUpper = "EXCEL" Then
Dim myAppCpu As PerformanceCounter = New PerformanceCounter("Process", "% Processor Time", "EXCEL", True)
Dim pct As Double = myAppCpu.NextValue()
' Console.WriteLine("EXCEL'S CPU % = " & pct)
Thread.Sleep(250)
If pct = 0.0 Then
pExcelProcess.Kill()
End If
End If
Next
Web.config
<identity impersonate="true" userName="uniadmin" password="UKS@137"/>
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=uksidr07;user id=sa;password=sa" cookieless="false" timeout="60"/>
<add key="PathDb" value="uid=uks;password=uks; database=OES_Final1; server=localhost;Min Pool Size=300;Max Pool Size=700;Connection Timeout=30; Integrated security=false"/>
请向我建议可以一次保存web.config的解决方案。