Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.44 KB | None | 0 0
  1. //every 60 seconds
  2.  
  3. Process[] procs;
  4. procs = Process.GetProcessesByName(appName);
  5. List<int> pidsRunning = new List<int>();
  6.  
  7. foreach(Process p in procs){
  8. pidsRunning.add(p.id);
  9. //other gathering of data and command line arguments
  10. }
  11.  
  12. foreach(int pid in pidsLast){
  13. if(!pidsRunning.Contains(pid)){
  14. //do stuff if not running
  15. }
  16. }
  17.  
  18. pidsRunning = pidsLast;
  19.  
  20. Program has stopped responding
  21. details:
  22.  
  23. Problem signature:
  24. Problem Event Name: APPCRASH
  25. Application Name: app.exe
  26. Application Version: 1.0.0.0
  27. Application Timestamp: 500efec6
  28. Fault Module Name: mshtml.dll
  29. Fault Module Version: 8.0.7600.17267
  30. Fault Module Timestamp: 5131882e
  31. Exception Code: c0000005
  32. Exception Offset: 00429796
  33. OS Version: 6.1.7600.2.0.0.274.10
  34. Locale ID: 1033
  35. Additional Information 1: 0a9e
  36. Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  37. Additional Information 3: 0a9e
  38. Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
  39.  
  40. - p {System.Diagnostics.Process (app)} System.Diagnostics.Process
  41. - base {System.Diagnostics.Process (app)} System.ComponentModel.Component {System.Diagnostics.Process}
  42. + base {System.Diagnostics.Process (app)} System.MarshalByRefObject {System.Diagnostics.Process}
  43. Container null System.ComponentModel.IContainer
  44. Site null System.ComponentModel.ISite
  45. + Static members
  46. + Non-Public members
  47. BasePriority 8 int
  48. EnableRaisingEvents false bool
  49. + ExitCode 'p.ExitCode' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException}
  50. + ExitTime 'p.ExitTime' threw an exception of type 'System.InvalidOperationException' System.DateTime {System.InvalidOperationException}
  51. + Handle 2368 System.IntPtr
  52. HandleCount 614 int
  53. HasExited false bool
  54. Id 4148 int
  55. MachineName "." string
  56. + MainModule {System.Diagnostics.ProcessModule (app.exe)} System.Diagnostics.ProcessModule
  57. + MainWindowHandle 1771888 System.IntPtr
  58. MainWindowTitle "C:\app.exe" string
  59. + MaxWorkingSet 1413120 System.IntPtr
  60. + MinWorkingSet 204800 System.IntPtr
  61. + Modules {System.Diagnostics.ProcessModuleCollection} System.Diagnostics.ProcessModuleCollection
  62. NonpagedSystemMemorySize 59684 int
  63. NonpagedSystemMemorySize64 59684 long
  64. PagedMemorySize 63553536 int
  65. PagedMemorySize64 63553536 long
  66. PagedSystemMemorySize 490456 int
  67. PagedSystemMemorySize64 490456 long
  68. PeakPagedMemorySize 69619712 int
  69. PeakPagedMemorySize64 69619712 long
  70. PeakVirtualMemorySize 386330624 int
  71. PeakVirtualMemorySize64 386330624 long
  72. PeakWorkingSet 91586560 int
  73. PeakWorkingSet64 91586560 long
  74. PriorityBoostEnabled true bool
  75. PriorityClass Normal System.Diagnostics.ProcessPriorityClass
  76. PrivateMemorySize 63553536 int
  77. PrivateMemorySize64 63553536 long
  78. + PrivilegedProcessorTime {00:00:20.7793332} System.TimeSpan
  79. ProcessName "app" string
  80. + ProcessorAffinity 255 System.IntPtr
  81. Responding true bool
  82. SessionId 2 int
  83. + StandardError 'p.StandardError' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
  84. + StandardInput 'p.StandardInput' threw an exception of type 'System.InvalidOperationException' System.IO.StreamWriter {System.InvalidOperationException}
  85. + StandardOutput 'p.StandardOutput' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
  86. + StartInfo {System.Diagnostics.ProcessStartInfo} System.Diagnostics.ProcessStartInfo
  87. + StartTime {10/5/2013 2:19:53 PM} System.DateTime
  88. SynchronizingObject null System.ComponentModel.ISynchronizeInvoke
  89. + Threads {System.Diagnostics.ProcessThreadCollection} System.Diagnostics.ProcessThreadCollection
  90. + TotalProcessorTime {00:07:39.5633459} System.TimeSpan
  91. + UserProcessorTime {00:07:18.7840127} System.TimeSpan
  92. VirtualMemorySize 378003456 int
  93. VirtualMemorySize64 378003456 long
  94. WorkingSet 88723456 int
  95. WorkingSet64 88723456 long
  96. + Static members
  97. - Non-Public members
  98. + base {System.Diagnostics.Process (app)} System.ComponentModel.Component {System.Diagnostics.Process}
  99. Associated true bool
  100. disposed false bool
  101. error null System.Diagnostics.AsyncStreamReader
  102. ErrorDataReceived null System.Diagnostics.DataReceivedEventHandler
  103. errorStreamReadMode undefined System.Diagnostics.Process.StreamReadMode
  104. exitCode 259 int
  105. exited false bool
  106. + exitTime {1/1/0001 12:00:00 AM} System.DateTime
  107. haveExitTime false bool
  108. haveMainWindow true bool
  109. havePriorityBoostEnabled true bool
  110. havePriorityClass true bool
  111. haveProcessHandle true bool
  112. haveProcessId true bool
  113. haveProcessorAffinity true bool
  114. haveResponding false bool
  115. haveWorkingSetLimits true bool
  116. isRemoteMachine false bool
  117. m_processAccess 2035711 int
  118. + m_processHandle {Microsoft.Win32.SafeHandles.SafeProcessHandle} Microsoft.Win32.SafeHandles.SafeProcessHandle
  119. machineName "." string
  120. mainWindowHandle 1771888 System.IntPtr
  121. mainWindowTitle "C:\app.exe" string
  122. maxWorkingSet 1413120 System.IntPtr
  123. minWorkingSet 204800 System.IntPtr
  124. + modules {System.Diagnostics.ProcessModuleCollection} System.Diagnostics.ProcessModuleCollection
  125. onExited null System.EventHandler
  126. + OperatingSystem {Microsoft Windows NT 6.1.7600.0} System.OperatingSystem
  127. + operatingSystem {Microsoft Windows NT 6.1.7600.0} System.OperatingSystem
  128. output null System.Diagnostics.AsyncStreamReader
  129. OutputDataReceived null System.Diagnostics.DataReceivedEventHandler
  130. outputStreamReadMode undefined System.Diagnostics.Process.StreamReadMode
  131. pendingErrorRead false bool
  132. pendingOutputRead false bool
  133. priorityBoostEnabled true bool
  134. priorityClass Normal System.Diagnostics.ProcessPriorityClass
  135. processId 4148 int
  136. processInfo {System.Diagnostics.ProcessInfo} System.Diagnostics.ProcessInfo
  137. processorAffinity 255 System.IntPtr
  138. raisedOnExited false bool
  139. registeredWaitHandle null System.Threading.RegisteredWaitHandle
  140. responding true bool
  141. signaled false bool
  142. standardError null System.IO.StreamReader
  143. standardInput null System.IO.StreamWriter
  144. standardOutput null System.IO.StreamReader
  145. - startInfo {System.Diagnostics.ProcessStartInfo} System.Diagnostics.ProcessStartInfo
  146. Arguments "" string
  147. CreateNoWindow false bool
  148. Domain "" string
  149. + EnvironmentVariables {System.Collections.Specialized.StringDictionaryWithComparer} System.Collections.Specialized.StringDictionary {System.Collections.Specialized.StringDictionaryWithComparer}
  150. ErrorDialog false bool
  151. + ErrorDialogParentHandle 0 System.IntPtr
  152. FileName "" string
  153. LoadUserProfile false bool
  154. + Password null System.Security.SecureString
  155. RedirectStandardError false bool
  156. RedirectStandardInput false bool
  157. RedirectStandardOutput false bool
  158. + StandardErrorEncoding null System.Text.Encoding
  159. + StandardOutputEncoding null System.Text.Encoding
  160. UserName "" string
  161. UseShellExecute true bool
  162. Verb "" string
  163. Verbs {string[0]} string[]
  164. WindowStyle Normal System.Diagnostics.ProcessWindowStyle
  165. WorkingDirectory "" string
  166. + Non-Public members
  167. synchronizingObject null System.ComponentModel.ISynchronizeInvoke
  168. - threads {System.Diagnostics.ProcessThreadCollection} System.Diagnostics.ProcessThreadCollection
  169. - base {System.Diagnostics.ProcessThreadCollection} System.Collections.ReadOnlyCollectionBase {System.Diagnostics.ProcessThreadCollection}
  170. Count 36 int
  171. - Non-Public members
  172. + [System.Diagnostics.ProcessThreadCollection] {System.Diagnostics.ProcessThreadCollection} System.Diagnostics.ProcessThreadCollection
  173. + InnerList Count = 36 System.Collections.ArrayList
  174. + list Count = 36 System.Collections.ArrayList
  175. System.Collections.ICollection.IsSynchronized false bool
  176. System.Collections.ICollection.SyncRoot {object} object
  177. waitHandle null System.Threading.WaitHandle
  178. watchForExit false bool
  179. watchingForExit false bool
  180.  
  181. Process[] procs;
  182. procs = Process.GetProcessesByName(appName);
  183. bool restartRequired = false;
  184. foreach (Process proc in procs) {
  185. if (!proc.Responding) {
  186. restartRequired = true;
  187. proc.Kill();
  188. break;
  189. }
  190. }
  191.  
  192. if (restartRequired) {
  193. Process procRun = new Process();
  194. procRun.StartInfo.FileName = @"C:Program FilesWinword.exe"
  195. procRun.Start();
  196. }
  197.  
  198. System.Reflection.Assembly app = System.Reflection.Assembly.LoadFrom("c:\Windows\ConsoleApp.exe");
  199. Type[] types = app.GetTypes();
  200. foreach (Type type in types)
  201. {
  202. System.Reflection.MethodInfo method = type.GetMethod("Main", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
  203. if (method != null)
  204. {
  205. tryAgain:
  206.  
  207. try
  208. {
  209. method.Invoke(null, null);
  210. }
  211. catch (Exception ex)
  212. {
  213. System.Threading.Thread.Sleep(2000); // Wait for 2 seconds if u wish..
  214. goto tryAgain;
  215. }
  216. break;
  217. }
  218. }
  219.  
  220. void init()
  221. {
  222. loadProcess();
  223. }
  224.  
  225. void loadProcess()
  226. {
  227. System.Threading.Thread.Sleep(2000);
  228. System.Diagnostics.Process prc = new System.Diagnostics.Process();
  229. prc.StartInfo.FileName = "C:\Windows\ConsoleApp.exe";
  230. prc.Exited += new EventHandler(prc_Exited); // Event Handler when the process is exited. (Mostly not working 4 me)
  231. prc.Start();
  232. }
  233.  
  234. void prc_Exited(object sender, EventArgs e)
  235. {
  236. loadProcess();
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement