c# - How to track application usage? (2) -


I asked about this question yesterday and got a great feedback / code example. The only problem is that I forgot to mention that I have to be forced to work with Net Framework 2.0 and can not use the list. Select (I consider leak namespace). Nobody works well for the list. Please select the one seen below:

  class program {struct process start-up process {get public process process; Set; } Get public datetime start-up; Set; } Public Datetime Execution {Get {Date Date} Now; // estimated value}} Public ProcessStartTimePair (Process P): This () {Process = P; {StartTime = p.StartTime; } Hold (System.ComponentModel.Win32Exception) {StartTime = DateTime.Now; // estimated value}}} static zero main (string [] args) {SqlConnection cnn = new SqlConnection (@ "data source = XXXXXX; initial catalog = XXXXXX; user id = XXXX; password = XXXX"); & Lt; ProcessStartTimePair & gt; Known process = new list & lt; ProcessStartTimePair & gt; (); Process (Process.GetProcesses) Process P) (if (!! Process.x (> = x.Process.Id) .company (PIID)) {knownProcesses.Add (New Process Start Time (P) ); //Console.WriteLine (the new process inherent: "+ p.ProcessName");}} for (int i = 0; i & lt; known process.account; i ++) {ProcessStartTimePair pair = known process [i ]; {If (pair.Process.HasExited) has exited {Console.WriteLine (pair.Process.ProcessName + ") ({0} to {1}).", Pair StartTime.ToString ( ), Pair .timetime (wired)); KnownProcesses.Remove (pair); I--; // List modified, 1 item less / Toodoo: Store information in database in the string sql = "insert in procs (machine, login, process, start_time, end_time)"; Sql + = "value" (+ "+ environment .mikinam +", "+ +" system security.independentity.gatecurrent () .name.tostring (). Split ('\\') [1] + " "," "+ Pair.progress.prinionname +" ',' '+ pair, starttime.Toastring () + "', '" + pair. Extensiontime.tostring () + "');"; SQL Commands CMD = New SQL Commands (SKL, CNN); Try {cnn.Open (); Cmd.ExecuteNonQuery (); } Hold (exception before) {//Console.WriteLine(ex.Message); } Finally {cnn.close (); }}} Hold (System.ComponentModel.Win32Exception) {// Check that the process is still in process. GetProcesses () // The process is probably a system process}} //Console.WriteLine (); System.Threading.Thread.Sleep (5000); }}}}}}  

I'm not sure that ID's datatype would be an integer, You get this idea:

  list & lt; Int & gt; IdList = new list & lt; Int & gt; (); Forrest (Processstime Timer Process in Known Process) {idList.Add (proc.Process.Id); } If (idList.Contains (p.Id)) {// ...}  

You have to work to get your ID list.

Besides, this is usually a better idea to edit your original question, and leaves comments on others' answers.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -