Force EditorWindow to stay opened?

How can I force a custom EditorWindow to be opened/docked? I’ve tried something like this:

void OnDestroy() {
    GetWindow<CustomWindowThing>();
}

and it kind of works, but then it doesn’t. I think the problem is that I need to somehow do it the next frame, after the window has been closed. But then it can’t do that, because the window is closed… Is there some other way to open up a new window if that window is closed?

If you’re wondering why I need this, it’s because I need the update of a window to be always called. Is there another way without needing the window to be docked at all?

It makes no sense to force a window to stay open. If you simply need an update function that runs in the background, you can use the update delegate of the EditorApplication class. You can subscribe to it from a static class with InitializeOnLoad:

[InitializeOnLoad]
public class SomeClass
{
    // InitializeOnLoad will cause the static constructor to be called automatically
    static SomeClass()
    {
        EditorApplication.update += OnUpdate;
    }
    void OnUpdate()
    {
        // Called about 100 times per sec.
    }
}

Maybe this could work, but I don’t know if static coroutine’s are possible.

[MenuItem("...")]
void Init()
{
   ...
}
...
void OnDestroy()
{
   StartCoroutine(MyWindow.Coroutine());
}
...
static IEnumerator Coroutine()
{
   yield return new WaitForSeconds(Time.deltaTime);
   Init();
}