Changeset 6 for trunk/MainForm.cs
- Timestamp:
- Nov 5, 2004, 2:59:12 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MainForm.cs
r5 r6 19 19 private ArrayList _parts; 20 20 private String _facePath; 21 21 private System.Windows.Forms.Timer _updateTimer; 22 Int32 prevUsage; 23 PerformanceCounter cpuCount; 24 // PerformanceCounter pageoutCount; 25 // PerformanceCounter pageinCount; 26 22 27 public MainForm() 23 28 { … … 29 34 _property = PropertyList.load(Path.Combine(_facePath,"faceDef.plist")); 30 35 _parts = (ArrayList)_property["parts"]; 36 prevUsage = -10; 31 37 32 (new Thread(new ThreadStart(CountProcessorUsage))).Start(); 38 cpuCount = new PerformanceCounter(); 39 cpuCount.CategoryName = "Processor"; 40 cpuCount.CounterName = "% Processor Time"; 41 cpuCount.InstanceName = "_Total"; 42 43 // pageoutCount = new PerformanceCounter(); 44 // pageoutCount.CategoryName = "Memory"; 45 // pageoutCount.CounterName = "Pages Output/sec"; 46 // 47 // pageinCount = new PerformanceCounter(); 48 // pageinCount.CategoryName = "Memory"; 49 // pageinCount.CounterName = "Pages Input/sec"; 50 51 _updateTimer = new System.Windows.Forms.Timer(); 52 _updateTimer.Interval = 1000; 53 _updateTimer.Tick += new EventHandler(this.CountProcessorUsage); 54 _updateTimer.Start(); 33 55 } 34 56 … … 72 94 } 73 95 74 p rivate void CountProcessorUsage()96 public void CountProcessorUsage(object sender, EventArgs e) 75 97 { 76 PerformanceCounter perfCount = new PerformanceCounter(); 77 perfCount.CategoryName = "Processor"; 78 perfCount.CounterName = "% Processor Time"; 79 perfCount.InstanceName = "_Total"; 98 Int32 usage = (Int32)cpuCount.NextValue(); 99 // Int32 pagein = (Int32)pageinCount.NextValue(); 100 // Int32 pageout = (Int32)pageoutCount.NextValue(); 80 101 81 PerformanceCounter pageoutCount = new PerformanceCounter(); 82 pageoutCount.CategoryName = "Memory"; 83 pageoutCount.CounterName = "Pages Output/sec"; 102 // Console.WriteLine("Processor: {0}% (pattern: {1}) {2} {3}", usage, usage/10, pagein, pageout); 103 if (usage >= 100) { 104 usage = 100; 105 } else if (usage < 0) { 106 usage = 0; 107 } 108 109 if (prevUsage/10 != usage/10) { 110 ArrayList patterns = (ArrayList)_property["pattern"]; 111 ArrayList patternCpu = (ArrayList)patterns[0]; 112 ArrayList facePattern = (ArrayList)patternCpu[usage/10]; 113 114 foreach (Int32 i in facePattern) { 115 Hashtable part = _parts[i] as Hashtable; 116 string filename = (string)part["filename"]; 117 string imgPath = Path.Combine(_facePath, filename); 118 using (Bitmap bitmap = new Bitmap(imgPath)) { 119 int x = (int)part["pos x"]; 120 int y = 128 - (int)part["pos y"] - bitmap.Size.Height; 121 this.Graphics.DrawImage(bitmap,x,y,bitmap.Size.Width,bitmap.Size.Height); 122 } 123 } 124 this.Update(); 125 } 126 127 prevUsage = usage; 128 } 84 129 85 PerformanceCounter pageinCount = new PerformanceCounter();86 pageinCount.CategoryName = "Memory";87 pageinCount.CounterName = "Pages Input/sec";88 89 Int32 prevUsage = -10;90 while (true) {91 Int32 usage = (Int32)perfCount.NextValue();92 Int32 pagein = (Int32)pageinCount.NextValue();93 Int32 pageout = (Int32)pageoutCount.NextValue();94 95 Console.WriteLine("Processor: {0}% (pattern: {1}) {2} {3}", usage, usage/10, pagein, pageout);96 if (usage >= 100) {97 usage = 100;98 } else if (usage < 0) {99 usage = 0;100 }101 102 // OÌp^[ÆÈXVÈE103 if (prevUsage/10 != usage/10) {104 ArrayList patterns = (ArrayList)_property["pattern"];105 ArrayList patternCpu = (ArrayList)patterns[0];106 ArrayList facePattern = (ArrayList)patternCpu[usage/10];107 108 foreach (Int32 i in facePattern) {109 Hashtable part = _parts[i] as Hashtable;110 string filename = (string)part["filename"];111 string imgPath = Path.Combine(_facePath, filename);112 using (Bitmap bitmap = new Bitmap(imgPath)) {113 int x = (int)part["pos x"];114 int y = 128 - (int)part["pos y"] - bitmap.Size.Height;115 this.Graphics.DrawImage(bitmap,x,y,bitmap.Size.Width,bitmap.Size.Height);116 }117 }118 this.Update();119 }120 121 prevUsage = usage;122 Thread.Sleep(1000);123 }124 125 }126 130 void doQuit(object sender, System.EventArgs e) 127 131 { 132 _updateTimer.Stop(); 128 133 Application.Exit(); 129 134 }
Note: See TracChangeset
for help on using the changeset viewer.