Coree.NETWindows
  • API
Show / Hide Table of Contents
  • Coree.NETWindows
    • KeyModifier
    • Keys
  • Coree.NETWindows.Classes
    • GlobalHotkey
  • Coree.NETWindows.NativeMethods
    • ConsoleManagement
    • ConsoleManagement.ConsoleColors
  • Coree.NETWindows.Services.PInvoke
    • IPInvokeService
    • PInvokeService
  • Coree.NETWindows.Utilities
    • MainContext

Class MainContext

Provides utility methods for managing the application's execution context, typically used within the Program.Main entry point.

Inheritance
object
MainContext
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Coree.NETWindows.Utilities
Assembly: Coree.NETWindows.dll
Syntax
public static class MainContext

Methods

| Edit this page View Source

AllocConsole()

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

  • Edit this page
  • View Source
In this article
Back to top