Help!

Items ItemAdd Outlook 2007 problem


Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Program Add-Ins RSS
Next:  printing error outlook express  
Author Message
Luk
External


Since: Jul 31, 2007
Posts: 4



PostPosted: Tue Jul 31, 2007 12:40 am    Post subject: Items ItemAdd Outlook 2007 problem
Archived from groups: microsoft>public>outlook>program_addins (more info?)

I wan't to have something like this:

I add items to Items collection and I do not wan't to handle the event (at
startup) and after I add some of those items I wan't to start handling the
ItemAdd event.

My code looks like this:

class Folder
{
private Outlook.Folder _folder = null;

private Outlook.Items _items = null;

private Logic.ContactsLogic _contactsLogic = null;

public Folder(Outlook.NameSpace outlook, string folderName)
{
Outlook.Folder defaultCalendarFolder =
(Outlook.Folder)outlook.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

_folder = GetFolder(defaultCalendarFolder, folderName);

_items = _folder.Items;

_contactsLogic = new ContactsLogic();

// In here I add some items to the folder
_contactsLogic.SynchronizeContacts(this);

HookUpEvents();
}


private void HookUpEvents()
{
_folder.BeforeFolderMove += new
Microsoft.Office.Interop.Outlook.MAPIFolderEvents_12_BeforeFolderMoveEventHandler(Folder_BeforeFolderMove);
_folder.BeforeItemMove += new
Microsoft.Office.Interop.Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);
_items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
_items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);

_eventsHookedUp = true;
}
}

Although I add event handlers after I add the Items to the collection (in
statement _contactsLogic.SynchronizeContacts(this); ) I still get to handle
them in Items_ItemAdd and I don't wan't to
Back to top
Ken Slovak - [MVP - Outlo
External


Since: Oct 17, 2003
Posts: 3213



PostPosted: Tue Jul 31, 2007 8:57 am    Post subject: Re: Items ItemAdd Outlook 2007 problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Is your call to SynchronizeContacts synchronous or asynchronous? If it's
waiting to return until the synching is finished you should not get ItemAdd
events.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Luk" <Luk.RemoveThis@discussions.microsoft.com> wrote in message
news:39774F53-9FF4-4583-82CE-20433D65218F@microsoft.com...
>I wan't to have something like this:
>
> I add items to Items collection and I do not wan't to handle the event (at
> startup) and after I add some of those items I wan't to start handling the
> ItemAdd event.
>
> My code looks like this:
>
> class Folder
> {
> private Outlook.Folder _folder = null;
>
> private Outlook.Items _items = null;
>
> private Logic.ContactsLogic _contactsLogic = null;
>
> public Folder(Outlook.NameSpace outlook, string folderName)
> {
> Outlook.Folder defaultCalendarFolder =
> (Outlook.Folder)outlook.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
>
> _folder = GetFolder(defaultCalendarFolder, folderName);
>
> _items = _folder.Items;
>
> _contactsLogic = new ContactsLogic();
>
> // In here I add some items to the folder
> _contactsLogic.SynchronizeContacts(this);
>
> HookUpEvents();
> }
>
>
> private void HookUpEvents()
> {
> _folder.BeforeFolderMove += new
> Microsoft.Office.Interop.Outlook.MAPIFolderEvents_12_BeforeFolderMoveEventHandler(Folder_BeforeFolderMove);
> _folder.BeforeItemMove += new
> Microsoft.Office.Interop.Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(Folder_BeforeItemMove);
> _items.ItemAdd += new
> Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
> _items.ItemChange += new
> Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
>
> _eventsHookedUp = true;
> }
> }
>
> Although I add event handlers after I add the Items to the collection (in
> statement _contactsLogic.SynchronizeContacts(this); ) I still get to
> handle
> them in Items_ItemAdd and I don't wan't to
Back to top
Luk
External


Since: Jul 31, 2007
Posts: 4



PostPosted: Tue Jul 31, 2007 8:57 am    Post subject: Re: Items ItemAdd Outlook 2007 problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

It's normal synchronous call :/

Maybe the problem is that it all hapens in the constructor?

"Ken Slovak - [MVP - Outlook]" wrote:

> Is your call to SynchronizeContacts synchronous or asynchronous? If it's
> waiting to return until the synching is finished you should not get ItemAdd
> events.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
Back to top
Luk
External


Since: Jul 31, 2007
Posts: 4



PostPosted: Tue Jul 31, 2007 8:57 am    Post subject: Re: Items ItemAdd Outlook 2007 problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Luk" wrote:

> It's normal synchronous call :/
>
> Maybe the problem is that it all hapens in the constructor?

No it isn't, even when I make HookUpEvents public and call it after Folder
object is constructed events still fire
Back to top
Ken Slovak - [MVP - Outlo
External


Since: Oct 17, 2003
Posts: 3213



PostPosted: Tue Jul 31, 2007 2:10 pm    Post subject: Re: Items ItemAdd Outlook 2007 problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

If the synch is finished when you add the event handlers no events from the
synch could possibly occur. It's not finished at the point where you're
adding the event handlers. That's my bet.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Luk" <Luk.DeleteThis@discussions.microsoft.com> wrote in message
news:CAC52D9D-475B-4031-A49B-AACBBBC2448F@microsoft.com...
>
>
> "Luk" wrote:
>
>> It's normal synchronous call :/
>>
>> Maybe the problem is that it all hapens in the constructor?
>
> No it isn't, even when I make HookUpEvents public and call it after Folder
> object is constructed events still fire
Back to top
Luk
External


Since: Jul 31, 2007
Posts: 4



PostPosted: Wed Aug 01, 2007 12:02 am    Post subject: Re: Items ItemAdd Outlook 2007 problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

funny thing...

_contactsLogic.SynchronizeContacts(this);
System.Windows.Forms.Application.DoEvents();
HookUpEvents();

Like this it works ok, events are queued in some way and fire as soon as
there is no other code executing?

"Ken Slovak - [MVP - Outlook]" wrote:

> If the synch is finished when you add the event handlers no events from the
> synch could possibly occur. It's not finished at the point where you're
> adding the event handlers. That's my bet.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
Back to top
Ken Slovak - [MVP - Outlo
External


Since: Oct 17, 2003
Posts: 3213



PostPosted: Wed Aug 01, 2007 9:52 am    Post subject: Re: Items ItemAdd Outlook 2007 problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

It looks like there might have been some problem in when the synch code was
releasing its unmanaged COM objects possibly. The garbage collector runs
asynchronously and that DoEvents might buy enough time for the garbage
collector to have released the objects.

If the synch code is working with COM objects are you calling
Marshal.ReleaseComObject on each one plus calling the garbage collector
explicitly and waiting for finalization before exiting the synch code?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Luk" <Luk RemoveThis @discussions.microsoft.com> wrote in message
news:9993A4C3-8230-4FB1-B4CA-826C6F4A1303@microsoft.com...
> funny thing...
>
> _contactsLogic.SynchronizeContacts(this);
> System.Windows.Forms.Application.DoEvents();
> HookUpEvents();
>
> Like this it works ok, events are queued in some way and fire as soon as
> there is no other code executing?
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Program Add-Ins All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum