Executing code before .NET's Main() method
问题 Is it possible to execute any user-provided code before the .NET Main method? It would be acceptable if the code had to be unmanaged. The reason for asking is that this might be a way to solve the problem of calling SetCurrentProcessExplicitAppUserModelID before any UI elements are displayed (as mentioned in Grouping separate processes in the Windows Taskbar) 回答1: In C# you can add a static constructor to the class which contains the main method. The code in the static constructor will be