# EventWatcher class

Namespace: [Rhino](https://developer.rhino3d.com/api/rhinocommon/namespace/rhino.md) · Assembly: [RhinoCommon](https://developer.rhino3d.com/api/rhinocommon/assembly/rhinocommon.md)

```cs
public class EventWatcher : IDisposable
```

An instance-based watcher for document and object events that can be notified for headless documents.

The static events on [RhinoDoc](https://developer.rhino3d.com/api/rhinocommon/type/rhino.rhinodoc.md) are never raised for headless documents (a headless document is one created with [RhinoDoc.CreateHeadless(string)](https://developer.rhino3d.com/api/rhinocommon/type/rhino.rhinodoc/createheadless.md) or [RhinoDoc.OpenHeadless(string)](https://developer.rhino3d.com/api/rhinocommon/type/rhino.rhinodoc/openheadless.md), as used by Rhino.Inside and Rhino.Compute). Create an [EventWatcher](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher.md) with `includeHeadlessDocuments` set to `true` to receive events for those documents as well.

IMPORTANT: When watching headless documents, events may be raised on a thread other than the main/UI thread, because headless documents can be created and read on background threads. Handlers must be thread-safe and must not assume they are running on the UI thread.

Call [EventWatcher.Dispose()](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/dispose.md) when the watcher is no longer needed to stop receiving events and release the underlying native watcher.

## Constructors

- [EventWatcher](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/ctor.md): Creates a new event watcher and begins watching.

## Finalizer

- [~EventWatcher](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/finalize.md): Releases the native watcher if [EventWatcher.Dispose()](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/dispose.md) was not called.

## Properties

- [IncludeHeadlessDocuments](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/includeheadlessdocuments.md): Gets whether this watcher also receives events for headless documents.

## Methods

- [Dispose](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/dispose.md): Stops watching and releases the underlying native watcher.

## Events

- [AddRhinoObject](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/addrhinoobject.md): Raised when a new object is added to a document.
- [BeginOpenDocument](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/beginopendocument.md): Raised when a document open operation begins.
- [CloseDocument](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/closedocument.md): Raised when a document is closed.
- [DeleteRhinoObject](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/deleterhinoobject.md): Raised when an object is deleted from a document.
- [EndOpenDocument](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/endopendocument.md): Raised when a document open operation ends.
- [NewDocument](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/newdocument.md): Raised when a new document is created.
- [PurgeRhinoObject](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/purgerhinoobject.md): Raised when an object is purged from a document.
- [ReplaceRhinoObject](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/replacerhinoobject.md): Raised when an object is about to be replaced.
- [UndeleteRhinoObject](https://developer.rhino3d.com/api/rhinocommon/type/rhino.eventwatcher/undeleterhinoobject.md): Raised when a previously deleted object is un-deleted.
