Changeset 6 for trunk


Ignore:
Timestamp:
Nov 5, 2004, 2:59:12 AM (19 years ago)
Author:
altba\rryu
Message:

更新処理を、スレッドをやめてSystem.Windows.Form.Timerで駆動するようにした。

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/AssemblyInfo.cs

    r1 r6  
    88// you compile.
    99
    10 [assembly: AssemblyTitle("")]
    11 [assembly: AssemblyDescription("")]
     10[assembly: AssemblyTitle("MacFace for Windows ‚¨ŽŽ‚µ”Å")]
     11[assembly: AssemblyDescription("ƒGƒ‚[ƒVƒ‡ƒiƒ‹CPUƒ[ƒ^MacFace")]
    1212[assembly: AssemblyConfiguration("")]
    13 [assembly: AssemblyCompany("")]
     13[assembly: AssemblyCompany("Team MacFace")]
    1414[assembly: AssemblyProduct("")]
    15 [assembly: AssemblyCopyright("")]
     15[assembly: AssemblyCopyright("Team MacFace")]
    1616[assembly: AssemblyTrademark("")]
    1717[assembly: AssemblyCulture("")]
  • trunk/MacFace.prjx

    r5 r6  
    1 <Project name="MacFace" standardNamespace="NewProject" description="" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#">
     1<Project name="MacFace" standardNamespace="MacFace" description="" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#">
    22  <Contents>
    33    <File name=".\AssemblyInfo.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
     
    55    <File name=".\AlphaForm.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
    66    <File name=".\MainForm.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
    7     <File name=".\MacFace.MainForm.resources" subtype="Code" buildaction="EmbedAsResource" dependson="" data="" />
    87  </Contents>
    98  <References />
     
    2120    </Configuration>
    2221    <Configuration runwithwarnings="False" name="Release">
    23       <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="True" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" noconfig="False" nostdlib="False" />
     22      <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="Standard" warninglevel="4" nowarn="" includedebuginformation="False" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="WinExe" definesymbols="" generatexmldocumentation="False" win32Icon="" noconfig="False" nostdlib="False" />
    2423      <Execution commandlineparameters="" consolepause="False" />
    2524      <Output directory=".\bin\Release" assembly="MacFace" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" />
  • trunk/MainForm.cs

    r5 r6  
    1919                private ArrayList _parts;
    2020                private String _facePath;
    21                
     21                private System.Windows.Forms.Timer _updateTimer;
     22                Int32 prevUsage;
     23                PerformanceCounter cpuCount;
     24//              PerformanceCounter pageoutCount;
     25//              PerformanceCounter pageinCount;
     26
    2227                public MainForm()
    2328                {
     
    2934                        _property = PropertyList.load(Path.Combine(_facePath,"faceDef.plist"));
    3035                        _parts = (ArrayList)_property["parts"];
     36                        prevUsage = -10;
    3137
    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();
    3355                }
    3456
     
    7294                }
    7395               
    74                 private void CountProcessorUsage()
     96                public void CountProcessorUsage(object sender, EventArgs e)
    7597                {
    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();
    80101
    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                }
    84129
    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                                 // Õp^[ƓȂXVȁE
    103                                 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                 }
    126130                void doQuit(object sender, System.EventArgs e)
    127131                {
     132                        _updateTimer.Stop();
    128133                        Application.Exit();
    129134                }
Note: See TracChangeset for help on using the changeset viewer.