Event trigers only first two times from FromRegion.

Status
Not open for further replies.
L

Lukasz

Hello,

I have a custom VSTO Addin with FormRegion. In that add_in I wan't to hook to the events triggered when a user presses Reply or Forward buttons of the inspector window running my FormRegion. To do this I do:

Private Sub ChoixProjetRegion_FormRegionShowing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing

If TypeOf (Me.OutlookItem) Is Outlook.MailItem AND Me.OutlookFormRegion.FormRegionMode = Outlook.OlFormRegionMode.olFormRegionRead Then

AddHandler CType(Me.OutlookItem, Outlook.MailItem).Reply, (AddressOf OutlookApplication_ItemReply)

End If

End Sub

Private Sub OutlookApplication_ItemReply(ByVal Item As Object, ByRef Cancel As Boolean)

MsgBox("here")

End Sub

It works. I see My Message Box when I press Reply. The Problem Is that it only works the first two times. ie, on the reply window I close it, and press Reply again on the original window and I get my MsgBox again, followed by the reply window. I close it again, and click on Reply thisr time, but this time the Reply window comes on without the MsgBox.

If I keep closing the Reply window and pressing the Reply button again a few times, eventually I'll get:

"COM object that has been separated from its underlying RCW cannot be used."

Does anyone know what's going on?.
 
Your handler is being eaten by the garbage collector. Make sure to declare

all relevant objects at class level, where they won't be garbage collected

and will remain in scope. You need a class level MailItem object that you

assign to that item and then you add the event handler to that class level

object.

"Lukasz" <lukaszmail[at]gmail[dot]com> wrote in message

news:%23OxIn0u4KHA.5848@TK2MSFTNGP06.phx.gbl...
> Hello,
> I have a custom VSTO Addin with FormRegion. In that add_in I wan't to hook
> to the events triggered when a user presses Reply or Forward buttons of
> the inspector window running my FormRegion. To do this I do:

> Private Sub ChoixProjetRegion_FormRegionShowing(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing

> If TypeOf (Me.OutlookItem) Is Outlook.MailItem AND
> Me.OutlookFormRegion.FormRegionMode =
> Outlook.OlFormRegionMode.olFormRegionRead Then
> AddHandler CType(Me.OutlookItem, Outlook.MailItem).Reply,
> (AddressOf OutlookApplication_ItemReply)

> End If

> End Sub

> Private Sub OutlookApplication_ItemReply(ByVal Item As Object, ByRef
> Cancel As Boolean)
> MsgBox("here")
> End Sub

> It works. I see My Message Box when I press Reply. The Problem Is that it
> only works the first two times. ie, on the reply window I close it, and
> press Reply again on the original window and I get my MsgBox again,
> followed by the reply window. I close it again, and click on Reply thisr
> time, but this time the Reply window comes on without the MsgBox.

> If I keep closing the Reply window and pressing the Reply button again a
> few times, eventually I'll get:

> "COM object that has been separated from its underlying RCW cannot be
> used."

> Does anyone know what's going on?. Submitted using
> https://forums.slipstick.com
 
That was it. Thank you Ken. It even took care of the COM error. My woes are not over though. Now the event handler executes between two and four times whenever I click on the Reply. Any idea why?

Thanks,

Lukasz

kenslovak wrote on Fri, 23 April 2010 10:58
> Your handler is being eaten by the garbage collector. Make sure to declare
> all relevant objects at class level, where they won't be garbage collected
> and will remain in scope. You need a class level MailItem object that you
> assign to that item and then you add the event handler to that class level
> object.

> >

>

> "Lukasz" <lukaszmail[at]gmail[dot]com> wrote in message
> news:%23OxIn0u4KHA.5848@TK2MSFTNGP06.phx.gbl...
> > Hello,
> > I have a custom VSTO Addin with FormRegion. In that add_in I wan't to hook
> > to the events triggered when a user presses Reply or Forward buttons of
> > the inspector window running my FormRegion. To do this I do:
> > Private Sub ChoixProjetRegion_FormRegionShowing(ByVal sender As Object,
> > ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing
> > If TypeOf (Me.OutlookItem) Is Outlook.MailItem AND
> > Me.OutlookFormRegion.FormRegionMode =
> > Outlook.OlFormRegionMode.olFormRegionRead Then
> > AddHandler CType(Me.OutlookItem, Outlook.MailItem).Reply,
> > (AddressOf OutlookApplication_ItemReply)
> > End If
> > End Sub
> > Private Sub OutlookApplication_ItemReply(ByVal Item As Object, ByRef
> > Cancel As Boolean)
> > MsgBox("here")
> > End Sub
> > It works. I see My Message Box when I press Reply. The Problem Is that it
> > only works the first two times. ie, on the reply window I close it, and
> > press Reply again on the original window and I get my MsgBox again,
> > followed by the reply window. I close it again, and click on Reply thisr
> > time, but this time the Reply window comes on without the MsgBox.
> > If I keep closing the Reply window and pressing the Reply button again a
> > few times, eventually I'll get:
> > "COM object that has been separated from its underlying RCW cannot be
> > used."
> > Does anyone know what's going on?. Submitted using
> > https://forums.slipstick.com
 
Are you removing the handler where the item that was showing the form region

is no longer current, and adding it back for any new items? When it fires

more than once is it for the same item each time? Any possibility that

you've added the same handler more than once for the same item?

"Lukasz" <lukaszmail[at]gmail[dot]com> wrote in message

news:eNA8Juv4KHA.3880@TK2MSFTNGP04.phx.gbl...
> That was it. Thank you Ken. It even took care of the COM error. My woes
> are not over though. Now the event handler executes between two and four
> times whenever I click on the Reply. Any idea why?

> Thanks,

> Lukasz
 
You got it again. I added RemoveHandler to the FormRegionClosed event and there's now only one call to my event handler.

Thank you very much.

Lukasz

kenslovak wrote on Fri, 23 April 2010 12:40
> Are you removing the handler where the item that was showing the form region
> is no longer current, and adding it back for any new items? When it fires
> more than once is it for the same item each time? Any possibility that
> you've added the same handler more than once for the same item?

> >

>

> "Lukasz" <lukaszmail[at]gmail[dot]com> wrote in message
> news:eNA8Juv4KHA.3880@TK2MSFTNGP04.phx.gbl...
> > That was it. Thank you Ken. It even took care of the COM error. My woes
> > are not over though. Now the event handler executes between two and four
> > times whenever I click on the Reply. Any idea why?
> > Thanks,
> > Lukasz
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Calendar events created on iPhone automatically changing default alert from 'None' to 'Time of Event' Using Outlook.com accounts in Outlook 0
T How to get an EVENT COLOR option in Outlook 2021 ? Using Outlook 0
J Cannot edit a calendar event received as an invitation Using Outlook 2
T Event Error on non existent Event. Using Outlook 2
J Event/Meeting in Outlook Does Not Align with SharePoint Calendar Using Outlook 5
P Calendar Day View only shows 1 all day event Using Outlook 0
G Event when creating task from mailitem Outlook VBA and Custom Forms 2
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
J Outlook 2010 Outlook/Win7 Client logging Event ID 36887 Using Outlook 0
K Recurring all day annual event Using Outlook 3
P Restore an individual all-day recurring event Using Outlook 2
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
K Working with Explorer.Close event Outlook VBA and Custom Forms 3
F Outlook 2016 call to Stop Timer Event Outlook VBA and Custom Forms 4
D Event ID issues Exchange Server Administration 2
J ItemChange event Outlook VBA and Custom Forms 11
T Outlook 2016 Calendar multiday event display Using Outlook 4
oliv- Treat once an email with the ItemAdd event in a shared mailbox Outlook VBA and Custom Forms 2
M Automatically create event in calendar when task is created Outlook VBA and Custom Forms 1
A UID field in iCal files - unique per-event or per-user or both? Using Outlook 2
D help with Item/Inspector close event Outlook VBA and Custom Forms 1
B on flag message event - create task Outlook VBA and Custom Forms 22
Diane Poremsky Change the All Day Event Default Free/Busy to "Busy" Using Outlook 3
C Calendar - Centering an event in Outlook? Using Outlook 1
J Outlook calendar...How to add an event or appointment without a border around it? Using Outlook 9
J Create Calendar Alert Event form Mail Subject line? Using Outlook 4
S Item Add Event fires intermittently Outlook VBA and Custom Forms 3
R Why is a meeting organizer me and not the creator of the event? Using Outlook 1
V Calendar event acting odd Using Outlook 7
G Capture "forward event" ? Outlook VBA and Custom Forms 11
P Change the Outlook.com "from" address for calendar event invites Using Outlook 9
20 Ton Squirrel Detect Application_Startup event completion Outlook VBA and Custom Forms 1
L Outlook 2007 All Day Event Using Outlook 27
I Event listener for deleted items Using Outlook 6
M Save Attachments Event? Using Outlook 0
Commodore Calendar Folder property is missing - Event 27 Using Outlook 11
G Quit event code - 2007 Using Outlook 3
J Capturing forward event when multiple items are selected Using Outlook 0
P Trying to get 'Calendar Name' to appear like 'Subject' and 'Location' in event Using Outlook 0
G What event happens when you open 2 copies of your inbox? Using Outlook 5
D Adding a participant automatically to a calendar event Using Outlook 1
H Changing Organizer of event (for single to total calendar move; long way ) Exchange Server Administration 4
N Combobox in outlook add ons toolbar not firing event on main window resized Using Outlook 3
D Extracting Location info from All Day Event in mailboxes into webpage Exchange Server Administration 3
H Conflicts with other event in calendar ( outlook 2007 &amp; 2010) Using Outlook 0
B Restoring Deleted Recurring Event AND Notes Using Outlook 8
Q Looking for Outlook 2010 Close Event Id Exchange Server Administration 1
S Outlook Recurring event Using Outlook 1
D Task and Event View in Outlook 2010? Using Outlook 3
G item_send event Outlook VBA and Custom Forms 4

Similar threads

Back
Top