Changeset 1562


Ignore:
Timestamp:
1/18/2010 6:11:46 AM (4 years ago)
Author:
lowjoel
Message:

Move the SetThreadExecutionState? function to the Power class. Addresses #284: Eraser.Util rewrite

Location:
branches/eraser6/CodeReview/Eraser.Util
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/CodeReview/Eraser.Util/KernelApi.cs

    r1560 r1562  
    148148                } 
    149149            } 
    150         } 
    151  
    152         /// <summary> 
    153         /// Enables an application to inform the system that it is in use, thereby 
    154         /// preventing the system from entering sleep or turning off the display 
    155         /// while the application is running. 
    156         /// </summary> 
    157         /// <param name="executionState">The thread's execution requirements. This 
    158         /// parameter can be one or more of the EXECUTION_STATE values.</param> 
    159         /// <returns>If the function succeeds, the return value is the previous 
    160         /// thread execution state. 
    161         ///  
    162         /// If the function fails, the return value is NULL.</returns> 
    163         /// <remarks>The system automatically detects activities such as local keyboard 
    164         /// or mouse input, server activity, and changing window focus. Activities 
    165         /// that are not automatically detected include disk or CPU activity and 
    166         /// video display. 
    167         ///  
    168         /// Calling SetThreadExecutionState without ES_CONTINUOUS simply resets 
    169         /// the idle timer; to keep the display or system in the working state, 
    170         /// the thread must call SetThreadExecutionState periodically. 
    171         ///  
    172         /// To run properly on a power-managed computer, applications such as fax 
    173         /// servers, answering machines, backup agents, and network management 
    174         /// applications must use both ES_SYSTEM_REQUIRED and ES_CONTINUOUS when 
    175         /// they process events. Multimedia applications, such as video players 
    176         /// and presentation applications, must use ES_DISPLAY_REQUIRED when they 
    177         /// display video for long periods of time without user input. Applications 
    178         /// such as word processors, spreadsheets, browsers, and games do not need 
    179         /// to call SetThreadExecutionState. 
    180         ///  
    181         /// The ES_AWAYMODE_REQUIRED value should be used only when absolutely 
    182         /// necessary by media applications that require the system to perform 
    183         /// background tasks such as recording television content or streaming media 
    184         /// to other devices while the system appears to be sleeping. Applications 
    185         /// that do not require critical background processing or that run on 
    186         /// portable computers should not enable away mode because it prevents 
    187         /// the system from conserving power by entering true sleep. 
    188         ///  
    189         /// To enable away mode, an application uses both ES_AWAYMODE_REQUIRED and 
    190         /// ES_CONTINUOUS; to disable away mode, an application calls 
    191         /// SetThreadExecutionState with ES_CONTINUOUS and clears 
    192         /// ES_AWAYMODE_REQUIRED. When away mode is enabled, any operation that 
    193         /// would put the computer to sleep puts it in away mode instead. The computer 
    194         /// appears to be sleeping while the system continues to perform tasks that 
    195         /// do not require user input. Away mode does not affect the sleep idle 
    196         /// timer; to prevent the system from entering sleep when the timer expires, 
    197         /// an application must also set the ES_SYSTEM_REQUIRED value. 
    198         ///  
    199         /// The SetThreadExecutionState function cannot be used to prevent the user 
    200         /// from putting the computer to sleep. Applications should respect that 
    201         /// the user expects a certain behavior when they close the lid on their 
    202         /// laptop or press the power button. 
    203         ///  
    204         /// This function does not stop the screen saver from executing.  
    205         /// </remarks> 
    206         public static ThreadExecutionState SetThreadExecutionState( 
    207             ThreadExecutionState executionState) 
    208         { 
    209             return (ThreadExecutionState)NativeMethods.SetThreadExecutionState( 
    210                 (NativeMethods.EXECUTION_STATE)executionState); 
    211150        } 
    212151 
     
    268207        } 
    269208    } 
    270  
    271     public enum ThreadExecutionState 
    272     { 
    273         /// <summary> 
    274         /// No specific state 
    275         /// </summary> 
    276         None = 0, 
    277  
    278         /// <summary> 
    279         /// Enables away mode. This value must be specified with ES_CONTINUOUS. 
    280         ///  
    281         /// Away mode should be used only by media-recording and media-distribution 
    282         /// applications that must perform critical background processing on 
    283         /// desktop computers while the computer appears to be sleeping. 
    284         /// See remarks. 
    285         ///  
    286         /// Windows Server 2003 and Windows XP/2000: ES_AWAYMODE_REQUIRED is 
    287         /// not supported. 
    288         /// </summary> 
    289         AwayModeRequired = (int)NativeMethods.EXECUTION_STATE.ES_AWAYMODE_REQUIRED, 
    290  
    291         /// <summary> 
    292         /// Informs the system that the state being set should remain in effect 
    293         /// until the next call that uses ES_CONTINUOUS and one of the other 
    294         /// state flags is cleared. 
    295         /// </summary> 
    296         Continuous = unchecked((int)NativeMethods.EXECUTION_STATE.ES_CONTINUOUS), 
    297  
    298         /// <summary> 
    299         /// Forces the display to be on by resetting the display idle timer. 
    300         /// </summary> 
    301         DisplayRequired = (int)NativeMethods.EXECUTION_STATE.ES_DISPLAY_REQUIRED, 
    302  
    303         /// <summary> 
    304         /// Forces the system to be in the working state by resetting the system 
    305         /// idle timer. 
    306         /// </summary> 
    307         SystemRequired = (int)NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED, 
    308  
    309         /// <summary> 
    310         /// This value is not supported. If ES_USER_PRESENT is combined with 
    311         /// other esFlags values, the call will fail and none of the specified 
    312         /// states will be set. 
    313         ///  
    314         /// Windows Server 2003 and Windows XP/2000: Informs the system that a 
    315         /// user is present and resets the display and system idle timers. 
    316         /// ES_USER_PRESENT must be called with ES_CONTINUOUS. 
    317         /// </summary> 
    318         UserPresent = (int)NativeMethods.EXECUTION_STATE.ES_USER_PRESENT 
    319     } 
    320209} 
Note: See TracChangeset for help on using the changeset viewer.