Class MainContext
Provides utility methods for managing the application's execution context, typically used within the Program.Main entry point.
Inherited Members
Namespace: Coree.NETWindows.Utilities
Assembly: Coree.NETWindows.dll
Syntax
public static class MainContext
Methods
| Edit this page View SourceAllocConsole()
Allocates a new console to the calling process.
Declaration
public static bool AllocConsole()
Returns
Type | Description |
---|---|
bool | A boolean value indicating whether the operation was successful. |
EnsureSingleInstance(Action, bool)
Ensures that only a single instance of the application is running. If a duplicate instance is detected, it executes a specified action and optionally exits the application.
Declaration
public static void EnsureSingleInstance(Action onDuplicateInstance, bool exit = true)
Parameters
Type | Name | Description |
---|---|---|
Action | onDuplicateInstance | An Action to be executed if a duplicate instance is found. This action is intended to provide a way to notify the user or log the event of a duplicate instance attempt. |
bool | exit | A boolean value indicating whether to exit the application if a duplicate instance is detected. Defaults to true, causing the application to exit. |
Remarks
This method attempts to create a named Mutex based on the application's entry assembly name. If the mutex cannot be created because it already exists, this indicates that an instance of the application is already running.
IsDebugBuild()
Determines if the current build is a debug build.
Declaration
public static bool IsDebugBuild()
Returns
Type | Description |
---|---|
bool | A boolean value indicating whether the current build has debugging features enabled, typically signifying a debug build. |
Remarks
This method checks for the presence of the DebuggableAttribute on the entry assembly and examines if JIT tracking is enabled, which is usually the case for builds compiled in a debug configuration. It's a useful check for altering behavior based on the build configuration without relying on preprocessor directives.
ProfileOptimization()
Enhances startup performance by enabling profile optimization.
Declaration
public static void ProfileOptimization()
Remarks
Call this method early in the Program.Main to optimize startup on subsequent runs.