Strange problem in outlook 2007

E

eranhef

Hi all,
i have created an outlook 2007 VSTO add-in.
In the add-in i'm creating a new calendar folder with 2 events:
1) Folder.BeforeItemMove event
2) Foldr.Items.ItemAdd event

the code is:
_sstFolder.BeforeItemMove += new

Microsoft.Office.Interop.Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(FolderBeforeItemMove);
_sstFolder.Items.ItemAdd += new

Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);

_sstFolder is Outlook.Folder and not Outlook.MapiFolder.

also i have a custom task pane in my add-in.

The Problem:
When i'm pressing the custom task pane, the 2 event of the folder is
disappearing!!
So, after i'm pressing the custom task pane i cannot create a new
appointment or delete an appointment.

Can anyone help me??

Tnx, Eran Hefer.
 
K

Ken Slovak - [MVP - Outlook]

What do you mean by "pressing the task pane"?

How are you adding the task pane? Are you using the VSTO CustomTaskPanes
collection?

Where are your event handlers? Are they in a class with global scope
throughout the addin, such as in ThisAddin? Make sure they aren't being
garbage collected. What about the Folder reference, could it be garbage
collected while you still need the reference? Is it declared at class level
in a class like ThisAddin that remains in scope?
 
E

eranhef

Hi Ken,
First of all - Tnx for your help!!
I've declared the Folder events (notice that the folder is
Outlook.Folder and not Outlook.MAPIFolder) in the ThisAddin class,
within the FolderSwitch event in the current active explorer. the
active explorer is kept as a global variable in the addin and never
nullified.

I'm creating the custom task pane (as a user control) using the VSTO
CustomTaskPanes collection.
When i'm pressing a DropDownList on my CustomTaskPane, the events of my
folder are both dead.
It seems that thay have been garbage collected, but i dont know why.
All the code (beside the User Control) is handled within the ThisAddin
class.
 
K

Ken Slovak - [MVP - Outlook]

So after you access the task pane the Folder events never fire again, or do
they fail to fire only when the task pane has focus?

I usually do something like this:

public partial class ThisAddin
{
private Outlook.Folder _Folder = null;

// blah, blah, more declarations and code
}

Not only the Explorer but also the Folder must be declared at class level,
otherwise the Folder may go out of scope. For example declaring the Folder
object inside FolderSwitch would let Folder go out of scope when that
procedure ends.

I can't say specifically about the CustomTaskPanes collection doing
anything, I've been avoiding that collection mostly since I discovered that
you can't set a Window for it. I've been using the Office.CustomTaskPane
objects so I can set what Window (Inspector or Explorer) I want the task
pane to be shown in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top