Process p = Process.GetCurrentProcess();

            
const double SPLIT = 0.01;
            
const int COUNT = 200;
            
const double PI = 3.14159265;
            
const int INTERVAL = 100;

            
double[] busySpan = new double[COUNT];  //array of busy times
            double[] idleSpan = new double[COUNT];  //array of idle times
            int half = INTERVAL / 2;

            
double radian = 0.0;
            
for (int i = 0; i < COUNT; i++)
            {
                busySpan[i] 
= (double)(half + (Math.Sin(PI * radian) * half));
                idleSpan[i] 
= INTERVAL - busySpan[i];
                radian 
+= SPLIT;
            }

            
double startTime = 0;
            
int j = 0;

            
while (true)
            {
                j 
= j % COUNT;

                startTime 
= Environment.TickCount;

                p.ProcessorAffinity 
= (IntPtr)0x0001;
                
while ((Environment.TickCount - startTime) <= busySpan[j]) ;

                p.ProcessorAffinity 
= (IntPtr)0x0002;
                
while ((Environment.TickCount - startTime) <= idleSpan[j]) ;

                j
++;
            }

 

相关文章:

  • 2021-12-26
  • 2021-08-02
  • 2021-11-29
  • 2021-12-05
  • 2022-12-23
  • 2022-03-05
  • 2021-11-18
  • 2021-06-02
猜你喜欢
  • 2022-01-24
  • 2021-12-24
  • 2021-12-29
  • 2022-12-23
  • 2021-11-19
  • 2021-08-20
  • 2021-06-02
相关资源
相似解决方案