# PerigeeApplication

## Application initialization

Both application starting points are nearly identical. The full callback has an IPC token and the initialize callback. [Both are described in Hello Perigee](/getting-started/hello-perigee.md).

```csharp
Application(string appName, string IPCCancelToken, Action<IConfiguration> initialize, Action<ThreadRegistry> taskConfiguration, CancellationTokenSource cancelSource = null, Task HostTask = null, string[] CommandLineArguments = null)
ApplicationNoInit(string appName, Action<ThreadRegistry> taskConfiguration, CancellationTokenSource cancelSource = null, Task HostTask = null, string[] CommandLineArguments = null)
```

You may also run the **`ApplicationNoInit`** as an async method as well:

```csharp
PerigeeApplication.ApplicationNoInit("async", async (c) => { 
    await Task.Delay(1000);
});
```

## Initialize outside a PerigeeApplication

Sometimes you need to initialize outside of the scope of a PerigeeApplication. We do this for API applications, blazor applications, and other scenarios where we need to call something before Perigee.

```csharp
static void Main(string[] args) {

   //To initialize perigee and the thread system:
   ThreadRegistry tr = ThreadRegistry.InstanceWithArgs(args);
   
   
   //Initializing credentials is not usually required unless changing working directories.
   //If you must initialize them, use either A or B:
   
   //A) Call instance
   var cinstance = CredentialStore.Instance;
   
   //B) Congiure
   CredentialStore.Configure()
}
```

## Host Statistics

To get information about the host it's running on, there is a single method:

```csharp
GetHostStatistics()
```

The response class, <mark style="color:blue;">**`HostStatistics`**</mark> contains properties for the machine it's running on including machine name, drive info, cpu time and running directory.&#x20;

## Exit event

To get an exit callback, use the helper method supplied.

After return is executed and the domain/service is about to unload, `OnExit` has a few seconds to perform any last tasks, like persisting data.&#x20;

```csharp
static void Main(string[] args)
{
    PerigeeApplication.OnExit(() => {
        Console.WriteLine("Exiting");
    });

    return;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.perigee.software/core-modules/perigeeapplication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
