Problem with DocumentDestroyed event
I have tried to register to this event :
Bricscad.ApplicationServices.Application.DocumentManager.DocumentDestroyed += new DocumentDestroyedEventHandler(DocumentManager_DocumentDestroyed);
but my EventHandler 'DocumentManager_DocumentDestroyed' is never called. What's wrong ?
Thanks, Marco.
Comments
-
Not sure, have a look at this code and see if it helps you.
[code]
using System;
using AcRx = Teigha.Runtime;
using AcAp = Bricscad.ApplicationServices;
[assembly: AcRx.CommandClass(typeof(CsMgdDocDestroyed.Commands))]
namespace CsMgdDocDestroyed
{
public static class Commands
{
static DocManEvents m_docManEvents = null;
[AcRx.CommandMethod("doit")]
static public void doit()
{
m_docManEvents = new DocManEvents();
}
public static void ShowException(System.Exception ex)
{
AcAp.Application.ShowAlertDialog(ex.Message);
}
public static void WriteEvent(string evnt)
{
AcAp.Application.ShowAlertDialog(evnt);
}
}
public class DocManEvents
{
private AcAp.DocumentCollection m_docMan;
public DocManEvents()
{
m_docMan = AcAp.Application.DocumentManager;
AddEvents();
}
public void AddEvents()
{
try
{
m_docMan.DocumentToBeDestroyed +=
new AcAp.DocumentCollectionEventHandler(
callback_DocumentToBeDestroyed);
m_docMan.DocumentDestroyed +=
new AcAp.DocumentDestroyedEventHandler(
callback_DocumentDestroyed);
}
catch (System.Exception ex)
{
Commands.ShowException(ex);
}
}
private void callback_DocumentToBeDestroyed
(Object sender, AcAp.DocumentCollectionEventArgs e)
{
try
{
if (e.Document != null)
Commands.WriteEvent(
String.Format(
"DocumentToBeDestroyed - {0}", e.Document.Window.Text));
else
Commands.WriteEvent(
String.Format("DocumentToBeDestroyed"));
}
catch (System.Exception ex)
{
Commands.ShowException(ex);
}
}
private void callback_DocumentDestroyed
(Object sender, AcAp.DocumentDestroyedEventArgs e)
{
try
{
Commands.WriteEvent(String.Format(
"DocumentDestroyed - {0}", e.FileName));
}
catch (System.Exception ex)
{
Commands.ShowException(ex);
}
}
}
}
[/code]
0