Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing code before .NET's Main() method

Tags:

c++

c#

.net

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)

like image 506
David Gardiner Avatar asked Dec 19 '12 05:12

David Gardiner


1 Answers

In C# you can add a static constructor to the class which contains the main method. The code in the static constructor will be executed before main.

like image 166
Andrew Cooper Avatar answered Sep 20 '22 10:09

Andrew Cooper