How do you check if unity is running in c#

I have a code in cutom editor and this code needs to be active if unity is running. For example.

Camera.main.SendMessage("iListen",viewPos);

When unity is not running it spits out an error “!IsPlayingOrAllowExecuteInEditMode ()”

This is why I need to add an if code; should look something like this -

if (UnityIsPlaying) Camera.main.SendMessage("iListen",viewPos);  // P.S. this is an example and does not work.

Use EditorApplication.isPlaying:

if (EditorApplication.isPlaying) {
  Camera.main.SendMessage("iListen",viewPos);
}