Editor instance consistency

Hello,
I have multiple problems with custom Editors I wrote for some of my component scripts.
There are times where I want an editor script to behave like a monobehaviour and let it make use of a update function, so I either subscribe on load to the editorwindow.update callback or wanna do it via editorguilayout.button press (Subscribe/unsubscribe). This approach works unless I switch the selection from the inspector view, if i switch from that inspector and reselect my gameobject with that custom editorscript i can not unsubscribe anymore. So I tried looking at the individual hashId of the current editorwindow and it differs everytime, when I switch selection from the inspector view. How can I have a consistent editorinstance which allows me to subscribe and unsubscribe to events without spawning a new editorinstances that carry their own subscribtions etc.?
Btw.: The other instance was with threading but since the symptoms are the same i would assume the root of the problem is also the same.
Hope someone can help me :slight_smile:
With regards Kath

So obviously right after asking this question here I found the easy workaround of just using the OnEnable and OnDisable Functions to unsubscribe or abort any callbacks/threads currently hold by the editorinstance.

[CustomEditor(typeof(someClass))]
public class MyCustomEditor : Editor
{
    Thread thread;

    public void OnEnable()
    {
        if (thread != null)
        {
            thread.Start();
        }
        else
        {
            this.thread = new Thread(Draw);
            this.thread.Start();
        }

        EditorApplication.update += Update;
    }
    public void OnDisable()
    {
        if (thread != null) thread.Abort();
        EditorApplication.update -= Update;
    }

    public void Update()
    {
//Some UpdateCode
        Debug.Log("Updating...");
    }

    public void Draw()
    {
        while (thread.IsAlive)
        {
            lock (somevalue)
            {
somevalue = someothervalue;
            }
            Thread.Sleep(2);
            Debug.Log("Thread running...");
        }
    }

}