Application event handler in .NET



I do not manage to get que application event handler on .NET.

I create a VB.NET class with the following elements

DimWithEvents oAppEv As SolidEdgeFramework.ApplicationEventsBut when I am trying to initilize the object, I got an error on the following line





objApp = GetSEApp()


oAppEv = objApp.ApplicationEvents

end sub

PrivateSub oApp_CloseDoc(ByVal oDoc AsObject) Handles oAppEv.BeforeDocumentCloseTryCatch ex As ExceptionEndTryEndSub










Do I have to do something special to do so.

I just want to get the documentClose Event, but it looks like in .NET things are not working the same way as in VB6





Posted by: Xabi Bikuna Losada
Post date: 6/23/2008 5:59:07 AM


RE: Application event handler in .NET

Imports SolidEdgeFrameworkImports System.Runtime.InteropServicesPublic Class Form1 Private objApplication As SolidEdgeFramework.Application Private WithEvents objAppEvents As SolidEdgeFramework.ISEApplicationEvents_Event Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try ' Connect to a running instance of Solid Edge objApplication = Marshal.GetActiveObject("SolidEdge.Application") ' Get a reference to the application events objAppEvents = objApplication.ApplicationEvents Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing If Not (objAppEvents Is Nothing) Then Marshal.ReleaseComObject(objAppEvents) objAppEvents = Nothing End If If Not (objApplication Is Nothing) Then Marshal.ReleaseComObject(objApplication) objApplication = Nothing End If End SubEnd Class


Posted by: Jason Newell
Post date: 6/23/2008 6:13:14 AM

RE: Application event handler in .NET


Thank you very much, for your quick answer.

It works fine now.


Posted by: Xabi Bikuna Losada
Post date: 6/23/2008 6:27:19 AM