You can do it in Main method. Just change its return-value-type to int instead of void and return your exit-code
static int Main(string[] args) { // something to do Console.ReadKey(); return 110; }
UPDATE:
To create a custom Main in WPF application, you should follow these steps:
First: unload the project by right-click on it in Solution Explorer and click on Unload Project
Modify the .csproj file by change the <ApplicationDefinition Include="App.xaml"> to this one: <Page Include="App.xaml">
Now you can create your own Main method in your project:
Sample Main method and App class:
public partial class App : Application { [STAThread] public static int Main() { App app = new App(); app.InitializeComponent(); var i = app.Run(); return i; } public App() : base() { } protected override void OnExit(ExitEventArgs e) { e.ApplicationExitCode = 110; base.OnExit(e); } }
ERRORLEVELwithout percent sign