A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Mapi Folder Items ItemChange event is not firing



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 5th 06, 12:36 PM posted to microsoft.public.outlook.program_vba
AtulSureka
external usenet poster
 
Posts: 11
Default Mapi Folder Items ItemChange event is not firing

Hi,

I have used the following code to Handle the EditItem Event of Task Items

using System;
using System.Data;
using System.Collections;
using Outlook = Microsoft.Office.Interop.Outlook;

public class MyClass
{
private static Outlook.NameSpace nSpace;
private static Outlook.MAPIFolder mapiFolder;

public static void Main(string[] args)
{
Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
nSpace = app.GetNamespace("MAPI");

mapiFolder =
nSpace.GetDefaultFolder(Outlook.OlDefaultFolders.o lFolderTasks);
mapiFolder.Items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(TaskItemChanged);

Console.ReadLine();
}

private static void TaskItemChanged(object Item)
{
Console.WriteLine("Item Has been chnaged");
}
}

However many times ItemChange event does not fire.
What can be the possible reasons?
Is there any work around for it?

- Atul Sureka

Ads
  #2  
Old February 5th 06, 06:23 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Mapi Folder Items ItemChange event is not firing

You need to keep MAPIFolder.Items collection in a global (class) variable to
make sure the GC does not release it.

public class MyClass
{
private static Outlook.NameSpace nSpace;
private static Outlook.Items Items
....

Items = mapiFolder.Items;
Items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(TaskItemChanged);

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"AtulSureka" wrote in message
...
Hi,

I have used the following code to Handle the EditItem Event of Task Items

using System;
using System.Data;
using System.Collections;
using Outlook = Microsoft.Office.Interop.Outlook;

public class MyClass
{
private static Outlook.NameSpace nSpace;
private static Outlook.MAPIFolder mapiFolder;

public static void Main(string[] args)
{
Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
nSpace = app.GetNamespace("MAPI");

mapiFolder =
nSpace.GetDefaultFolder(Outlook.OlDefaultFolders.o lFolderTasks);
mapiFolder.Items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(TaskItemChanged);

Console.ReadLine();
}

private static void TaskItemChanged(object Item)
{
Console.WriteLine("Item Has been chnaged");
}
}

However many times ItemChange event does not fire.
What can be the possible reasons?
Is there any work around for it?

- Atul Sureka



  #3  
Old February 5th 06, 06:24 PM posted to microsoft.public.outlook.program_vba
Josh Einstein
external usenet poster
 
Posts: 57
Default Mapi Folder Items ItemChange event is not firing

Due to the way .NET and COM interop works, you have to cache the Items
object in a field as well. Just having the MAPIFolder isn't enough because
each call to Items will return a different RCW (runtime callable wrapper)
which means your first one goes out of scope and is subsequently garbage
collected.

private Outlook.Items _items;

_items = _mapiFolder.Items;
_items.ItemChange += delegate { MessageBox.Show("item changed!"); };

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com


"AtulSureka" wrote in message
...
Hi,

I have used the following code to Handle the EditItem Event of Task Items

using System;
using System.Data;
using System.Collections;
using Outlook = Microsoft.Office.Interop.Outlook;

public class MyClass
{
private static Outlook.NameSpace nSpace;
private static Outlook.MAPIFolder mapiFolder;

public static void Main(string[] args)
{
Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
nSpace = app.GetNamespace("MAPI");

mapiFolder =
nSpace.GetDefaultFolder(Outlook.OlDefaultFolders.o lFolderTasks);
mapiFolder.Items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(TaskItemChanged);

Console.ReadLine();
}

private static void TaskItemChanged(object Item)
{
Console.WriteLine("Item Has been chnaged");
}
}

However many times ItemChange event does not fire.
What can be the possible reasons?
Is there any work around for it?

- Atul Sureka



  #4  
Old February 5th 06, 06:25 PM posted to microsoft.public.outlook.program_vba
Josh Einstein
external usenet poster
 
Posts: 57
Default Mapi Folder Items ItemChange event is not firing

Whoops, guess you beat me to it.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com


"Dmitry Streblechenko" wrote in message
...
You need to keep MAPIFolder.Items collection in a global (class) variable
to make sure the GC does not release it.

public class MyClass
{
private static Outlook.NameSpace nSpace;
private static Outlook.Items Items
...

Items = mapiFolder.Items;
Items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(TaskItemChanged);

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"AtulSureka" wrote in message
...
Hi,

I have used the following code to Handle the EditItem Event of Task Items

using System;
using System.Data;
using System.Collections;
using Outlook = Microsoft.Office.Interop.Outlook;

public class MyClass
{
private static Outlook.NameSpace nSpace;
private static Outlook.MAPIFolder mapiFolder;

public static void Main(string[] args)
{
Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
nSpace = app.GetNamespace("MAPI");

mapiFolder =
nSpace.GetDefaultFolder(Outlook.OlDefaultFolders.o lFolderTasks);
mapiFolder.Items.ItemChange += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemC hangeEventHandler(TaskItemChanged);

Console.ReadLine();
}

private static void TaskItemChanged(object Item)
{
Console.WriteLine("Item Has been chnaged");
}
}

However many times ItemChange event does not fire.
What can be the possible reasons?
Is there any work around for it?

- Atul Sureka





 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing duplicate recurring event calendar items Musawwir Spiegel Outlook - Calandaring 7 March 29th 06 03:56 PM
Junk E-mail folder - is there a way to create a rule to delete items in this folder older than X days? Jaycee Outlook - General Queries 1 February 22nd 06 04:54 PM
MapiFolder Items ItemChange is not firing AtulSureka Outlook - Using Forms 1 February 6th 06 04:32 PM
How do I get sent items to be shown in my sent items folder? Sue B Outlook - General Queries 8 January 28th 06 07:46 PM
Outlook Addin CommandBarButton Click Event Not Firing Stu Add-ins for Outlook 0 January 17th 06 02:10 AM


All times are GMT +1. The time now is 07:57 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.