<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Event handler triggered multiple times in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3094080#M60130</link>
    <description>&lt;P&gt;Took a while but I found my answer here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="http://forums.autodesk.com/t5/NET/Emulate-Properties-Dialog-by-selecting-object-on-screen/td-p/2526759"&gt;http://forums.autodesk.com/t5/NET/Emulate-Properties-Dialog-by-selecting-object-on-screen/td-p/2526759&lt;/A&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I needed the&amp;nbsp;ImpliedSelectionChanged﻿ event&lt;/P&gt;&lt;PRE&gt;AddHandler doc.ImpliedSelectionChanged, AddressOf Document_ImpliedSelectionChanged&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    Private Sub Document_ImpliedSelectionChanged(ByVal sender As [Object], ByVal e As EventArgs)
        Dim doc As Document = DirectCast(sender, Document)
        Dim ed As Editor = doc.Editor

        Dim sr As PromptSelectionResult = ed.SelectImplied()
        If sr.Value Is Nothing Then
            Return
        End If

        ed.WriteMessage(vbLf &amp;amp; "Selection Count: {0}", sr.Value.Count)
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 17 Jul 2011 07:14:37 GMT</pubDate>
    <dc:creator>SRSDS</dc:creator>
    <dc:date>2011-07-17T07:14:37Z</dc:date>
    <item>
      <title>Event handler triggered multiple times</title>
      <link>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093462#M60125</link>
      <description>&lt;P&gt;I have a SelectionAdded event handler that reacts three times when selecing a single block and once when deselecting it.&lt;/P&gt;&lt;P&gt;If there are two blocks in the drawing but only selected one it reacts 5 or 6 times.&lt;/P&gt;&lt;P&gt;And it reacts every time I pass the mouse over the selected block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to sidestep the events in the handler so that AutoCAD doesn't grind to a halt if I have multiple blocks in the drawing. And decide to move my mouse over all of them?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2011 17:28:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093462#M60125</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-07-15T17:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Event handler triggered multiple times</title>
      <link>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093520#M60126</link>
      <description>&lt;P&gt;You have to add a event handler for it fire.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe showing your code how you add them would help someone help you out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2011 17:53:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093520#M60126</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-15T17:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Event handler triggered multiple times</title>
      <link>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093612#M60127</link>
      <description>&lt;PRE&gt;Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.EditorInput
&amp;lt;Assembly: ExtensionApplication(GetType(VbExtApp))&amp;gt; 

Public Class VbExtApp
    Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

    Private DocMan As DocumentCollection

    'Initialize sub
    Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize

        DocMan = AcApp.DocumentManager

        AddHandler DocMan.DocumentCreated, AddressOf callback_documentCreated
        AddHandler DocMan.DocumentActivated, AddressOf callback_documentActivated

        Dim doc As Document
        For Each doc In DocMan
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            AddHandler db.ObjectModified, AddressOf callback_ObjectModified
            AddHandler db.ObjectAppended, AddressOf callback_ObjectAppended
            AddHandler db.ObjectErased, AddressOf callback_ObjectErased
            AddHandler ed.SelectionAdded, AddressOf callback_SelectionAdded
            ' AddHandler ed.SelectionRemoved, AddressOf callback_SelectionRemoved
        Next
        'Import Blocks
        ImportBlocks("D:\My Documents\Visual Studio Projects\Detailer\Blocks.dwg")

        'Load Palette
        Loading = True
        pal = New Palette()
        pal.LoadPalette()
        Loading = False
        'Initialise Thumbnail Class
        Dim thumb As ThumbNailClass
        thumb = New ThumbNailClass


    End Sub
    'SelectionAdded

    Public Sub callback_SelectionAdded(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.EditorInput.SelectionAddedEventArgs)
        'MsgBox("Selection Made")
        For Each objid As ObjectId In e.AddedObjects.GetObjectIds
            ID = objid
            ReDim Preserve ObjectCollection(0)
            ReDim Preserve ObjectCollection(0).Set_(0)
            ReDim Preserve ObjectCollection(0).Set_(0).View(0)
            ReDim Preserve ObjectCollection(0).Set_(0).Range(0)
            ReDim Preserve ObjectCollection(0).Set_(0).Label(0)

            NoViews = 0 : NoRanges = 0 : NoLabels = 0
            ObjectsSelected()
        Next
    End Sub


    'Terminate sub
    Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
        RemoveHandler DocMan.DocumentCreated, AddressOf callback_documentCreated
    End Sub

    Public Shared Sub callback_ObjectModified(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs)
        'MsgBox("Something was modified")
        ID = e.DBObject.ObjectId
        ModifyEventHander()
    End Sub


    Public Shared Sub callback_ObjectAppended(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs)
        'MsgBox("Something was Appended")
    End Sub

    Public Shared Sub callback_ObjectErased(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectErasedEventArgs)
        'MsgBox("Something was Erased")
        ID = e.DBObject.ObjectId
        DeleteEventHandler()
    End Sub

    Private Sub callback_documentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
        If e.Document = Nothing Then
            Exit Sub
        Else
            '   MsgBox("Document Created")
        End If

    End Sub

    Private Sub callback_documentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
        If e.Document = Nothing Then
            Exit Sub
        Else
            '    MsgBox("Document Active")
        End If
    End Sub

End Class&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2011 18:32:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093612#M60127</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-07-15T18:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Event handler triggered multiple times</title>
      <link>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093862#M60128</link>
      <description>&lt;P&gt;I just added break points on the ObjectModified and ObjectAppended to see which event was triggering it.&lt;/P&gt;&lt;P&gt;On starting the debug &amp;nbsp;they were triggered an enless number of times.&lt;/P&gt;&lt;P&gt;Computers are fast these days but I don't want my application to slow things down.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are there any step overs I should be considering in my code to handle these multiple fire events?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2011 21:58:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093862#M60128</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-07-15T21:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: Event handler triggered multiple times</title>
      <link>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093958#M60129</link>
      <description>&lt;P&gt;This is all very confusing.&lt;/P&gt;&lt;P&gt;If I press Escape with objects selected the&amp;nbsp;SelectionAdded﻿ event handler is triggered containing the selection instead of the SelectionRemoved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a handler that deals with the current selection which reacts after any objects are added or removed?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2011 08:07:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3093958#M60129</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-07-16T08:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Event handler triggered multiple times</title>
      <link>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3094080#M60130</link>
      <description>&lt;P&gt;Took a while but I found my answer here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="http://forums.autodesk.com/t5/NET/Emulate-Properties-Dialog-by-selecting-object-on-screen/td-p/2526759"&gt;http://forums.autodesk.com/t5/NET/Emulate-Properties-Dialog-by-selecting-object-on-screen/td-p/2526759&lt;/A&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I needed the&amp;nbsp;ImpliedSelectionChanged﻿ event&lt;/P&gt;&lt;PRE&gt;AddHandler doc.ImpliedSelectionChanged, AddressOf Document_ImpliedSelectionChanged&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    Private Sub Document_ImpliedSelectionChanged(ByVal sender As [Object], ByVal e As EventArgs)
        Dim doc As Document = DirectCast(sender, Document)
        Dim ed As Editor = doc.Editor

        Dim sr As PromptSelectionResult = ed.SelectImplied()
        If sr.Value Is Nothing Then
            Return
        End If

        ed.WriteMessage(vbLf &amp;amp; "Selection Count: {0}", sr.Value.Count)
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2011 07:14:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/event-handler-triggered-multiple-times/m-p/3094080#M60130</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-07-17T07:14:37Z</dc:date>
    </item>
  </channel>
</rss>

