/// <summary> /// A handler for the Idling event. /// </summary> /// <remarks> /// We keep the handler very simple. First we check /// if we still have the dialog. If not, we unsubscribe from Idling, /// for we no longer need it and it makes Revit speedier. /// If we do have the dialog around, we check if it has a request ready /// and process it accordingly. /// </remarks> /// public void IdlingHandler(object sender, IdlingEventArgs args) { UIApplication uiapp = sender as UIApplication; UIDocument uidoc = uiapp.ActiveUIDocument; if (m_MyForm.IsDisposed) { uiapp.Idling -= IdlingHandler; return; } else // dialog still exists { // fetch the request from the dialog RequestId requestId = m_MyForm.Request.Take(); if (requestId != RequestId.None) { try { // we take the request, if any was made, // and pass it on to the request executor RequestHandler.Execute(this, requestId); } finally { // The dialog may be in its waiting state; // make sure we wake it up even if we get an exception. m_MyForm.EnableButtons(IsLighterEnabled(), IsDarkerEnabled()); } } } return; }