# Statics

## Static Variables

Static variables in Wisej.NET are just regular C# static variables. They have the same value and are accessible across all client sessions. A static variable has one copy per AppDomain. So, if the AppDomain or AppPool resets, the value of the static variable resets.

You can create a static variable like so:

```csharp
public static string myStaticVariable = "hello";
```

## Static Events

In Wisej.NET, a static event is just a normal C# static event — and that means there is exactly one event + one subscriber list per application instance on the server, shared by all browser sessions. In other words, when static events in Wisej.NET fire, they fire in all sessions.

You can create a static event like so:

```csharp
public static event EventHandler MyStaticEvent;
```

And attach a handler to the event like so:

```csharp
MyStaticEvent += MyStaticEvent_Fired;

private void MyStaticEvent_Fired(object sender, EventArgs e)
{
    //code that runs when the event is fired
}
```

You can fire the event like so:

```csharp
MyStaticEvent?.Invoke(null, EventArgs.Empty);
```

Note that when a static event fires, it is out-of-context; it's associated with the sender's session. So if you want to do something session-specific like updating the UI when a static event fires, you’ll need to use `Application.Update`:

<pre class="language-csharp"><code class="lang-csharp">private void MyStaticEvent_Fired(object sender, EventArgs e)
{
<strong>    Application.Update(this, () => 
</strong>    { 
        //example UI updates
        button1.Enabled = true
<strong>        button1.Text = "New Text"; 
</strong><strong>        label1.Text = "New Text";
</strong>    });
}
</code></pre>

In our case, `this` represents the context of the current browser session. By passing in `this`, we tell the application to run in the context of our current browser session, which allows us to update the UI for that session.

{% hint style="info" %}
If the code in the event handler doesn't update the UI, you can also use Application.RunInContext() instead of Application.Update() in order to avoid pushing a UI update to the browser.
{% endhint %}


---

# 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.wisej.com/docs/concepts/statics.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.
