The best way to trigger update() in Editor mode?

I am trying to get coroutine to work (to update, eg. tick a few frames) in editor mode.

I know coroutine is not supposed to work in editor mode because the lack of consistent update loop. But I find using EditorUtility.SetDirty(target) in OnInspectorGUI works.

public override void OnInspectorGUI () {
  if (GUILayout.Button("Refresh")) {
     EditorUtility.SetDirty(target);
  }
}

If I keep clicking on the refresh button eventually the coroutine runs to completion.

My question: is it the best way? Obviously it’s a hack, but it seems to be the only solution besides entering play mode.

Don’t use a coroutine in the editor. I would instead do something like subscribe to EditorApplication.update in your Editor’s OnEnable() method, and unsubscribe in OnDisable(). You can then decide exactly when to execute whatever you’re doing in your event handler.