# 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](https://docs.perigee.software/getting-started/hello-perigee).

```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;
}
```
