NewInspecor event won't fire when accessing config file

  • Thread starter Thread starter ilan
  • Start date Start date
I

ilan

Hi,

I'm catching the event of opening a task.

in the event handler I'm accessing a config file (I
created Outlook.exe.config in the C:\Program
Files\Microsoft Office\OFFICE11 folder and added "MyVal"
value to it)
I'm getting the correct value from my config file but
it only happens once. The NewInspector event won't fire
again.

Ommiting the line that access the config file results with
this event fires normally.

Any suggestions?

I'm using Outlook 2003 win 2003.

This is the code I use:
namespace MyFirstOutlookAddin
{

using System;
using Microsoft.Office.Core;
using System.Windows.Forms;
using System.Reflection;
using Extensibility;
using System.Runtime.InteropServices;
using System.Configuration;
using System.IO;

[GuidAttribute("EADFD989-C91D-4E2C-9D76-
5DA414736ECD"), ProgId("MyFirstOutlookAddin.Connect")]
public class Connect : Object,
Extensibility.IDTExtensibility2
{
public Outlook.TaskItemClass
outlookItems ;
private Outlook.Application
applicationObject;
private object addInInstance;


public Connect()
{
}


public void OnConnection(object
application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject =
(Outlook.Application)application;
addInInstance = addInInst;

if (connectMode !=
Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref
custom);
}
MessageBox.Show("Connected1");
register();
}

public void register()
{
Outlook.NameSpace ns =

applicationObject.GetNamespace("MAPI");

Outlook.MAPIFolder TaskFolder =
ns.GetDefaultFolder

(Outlook.OlDefaultFolders.olFolderTasks);
TaskFolder.Items.ItemChange +=new
Outlook.ItemsEvents_ItemChangeEventHandler
(Items_ItemChange);


applicationObject.Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler
(Inspectors_NewInspector);

}
private void Connect_Open(ref bool Cancel)
{
MessageBox.Show("Connect_Open");

}

public void OnDisconnection
(Extensibility.ext_DisconnectMode disconnectMode, ref
System.Array custom)
{
MessageBox.Show("Disconnected");
if(disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref
custom);
}
applicationObject = null;

}

public void OnAddInsUpdate(ref
System.Array custom)
{
}

public void OnStartupComplete(ref
System.Array custom)
{
}

public void OnBeginShutdown(ref
System.Array custom)
{
}

private void Connect_FolderSwitch()
{

}

private void Items_ItemChange(object Item)
{
MessageBox.Show("Change");
}


private void Connect_ItemEvents_Event_Open
(ref bool Cancel)
{
MessageBox.Show
("Connect_ItemEvents_Event_Open");
try
{
string val=
ConfigurationSettings.AppSettings["myVal"];
}
catch(Exception ex)
{
throw ex;
}
Cancel = true;
}

private void Inspectors_NewInspector
(Outlook.Inspector Inspector)
{

outlookItems =
(Outlook.TaskItemClass)(Inspector.CurrentItem);
if (Inspector.CurrentItem is
Outlook.TaskItemClass)
{
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).ItemEvents_Event_Open +=new
Outlook.ItemEvents_OpenEventHandler
(Connect_ItemEvents_Event_Open);
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).Open+=new
Outlook.ItemEvents_10_OpenEventHandler(Connect_Open);
}
}

}
}
 
Store the inspectors collection as a class variable and change your code to

m_Inspectors = applicationObject.Inspectors;
m_Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);

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


ilan said:
Hi,

I'm catching the event of opening a task.

in the event handler I'm accessing a config file (I
created Outlook.exe.config in the C:\Program
Files\Microsoft Office\OFFICE11 folder and added "MyVal"
value to it)
I'm getting the correct value from my config file but
it only happens once. The NewInspector event won't fire
again.

Ommiting the line that access the config file results with
this event fires normally.

Any suggestions?

I'm using Outlook 2003 win 2003.

This is the code I use:
namespace MyFirstOutlookAddin
{

using System;
using Microsoft.Office.Core;
using System.Windows.Forms;
using System.Reflection;
using Extensibility;
using System.Runtime.InteropServices;
using System.Configuration;
using System.IO;

[GuidAttribute("EADFD989-C91D-4E2C-9D76-
5DA414736ECD"), ProgId("MyFirstOutlookAddin.Connect")]
public class Connect : Object,
Extensibility.IDTExtensibility2
{
public Outlook.TaskItemClass
outlookItems ;
private Outlook.Application
applicationObject;
private object addInInstance;


public Connect()
{
}


public void OnConnection(object
application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject =
(Outlook.Application)application;
addInInstance = addInInst;

if (connectMode !=
Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref
custom);
}
MessageBox.Show("Connected1");
register();
}

public void register()
{
Outlook.NameSpace ns =

applicationObject.GetNamespace("MAPI");

Outlook.MAPIFolder TaskFolder =
ns.GetDefaultFolder

(Outlook.OlDefaultFolders.olFolderTasks);
TaskFolder.Items.ItemChange +=new
Outlook.ItemsEvents_ItemChangeEventHandler
(Items_ItemChange);


applicationObject.Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler
(Inspectors_NewInspector);

}
private void Connect_Open(ref bool Cancel)
{
MessageBox.Show("Connect_Open");

}

public void OnDisconnection
(Extensibility.ext_DisconnectMode disconnectMode, ref
System.Array custom)
{
MessageBox.Show("Disconnected");
if(disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref
custom);
}
applicationObject = null;

}

public void OnAddInsUpdate(ref
System.Array custom)
{
}

public void OnStartupComplete(ref
System.Array custom)
{
}

public void OnBeginShutdown(ref
System.Array custom)
{
}

private void Connect_FolderSwitch()
{

}

private void Items_ItemChange(object Item)
{
MessageBox.Show("Change");
}


private void Connect_ItemEvents_Event_Open
(ref bool Cancel)
{
MessageBox.Show
("Connect_ItemEvents_Event_Open");
try
{
string val=
ConfigurationSettings.AppSettings["myVal"];
}
catch(Exception ex)
{
throw ex;
}
Cancel = true;
}

private void Inspectors_NewInspector
(Outlook.Inspector Inspector)
{

outlookItems =
(Outlook.TaskItemClass)(Inspector.CurrentItem);
if (Inspector.CurrentItem is
Outlook.TaskItemClass)
{
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).ItemEvents_Event_Open +=new
Outlook.ItemEvents_OpenEventHandler
(Connect_ItemEvents_Event_Open);
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).Open+=new
Outlook.ItemEvents_10_OpenEventHandler(Connect_Open);
}
}

}
}
 
Thank You Dmitry !!!
that was it.

I would greatly appreciate if you can explain what was the
problem, or give any links to information regarding this
issue.

Again, many thanks.

Ilan
-----Original Message-----
Store the inspectors collection as a class variable and change your code to

m_Inspectors = applicationObject.Inspectors;
m_Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler (Inspectors_NewInspector);

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


ilan said:
Hi,

I'm catching the event of opening a task.

in the event handler I'm accessing a config file (I
created Outlook.exe.config in the C:\Program
Files\Microsoft Office\OFFICE11 folder and added "MyVal"
value to it)
I'm getting the correct value from my config file but
it only happens once. The NewInspector event won't fire
again.

Ommiting the line that access the config file results with
this event fires normally.

Any suggestions?

I'm using Outlook 2003 win 2003.

This is the code I use:
namespace MyFirstOutlookAddin
{

using System;
using Microsoft.Office.Core;
using System.Windows.Forms;
using System.Reflection;
using Extensibility;
using System.Runtime.InteropServices;
using System.Configuration;
using System.IO;

[GuidAttribute("EADFD989-C91D-4E2C-9D76-
5DA414736ECD"), ProgId("MyFirstOutlookAddin.Connect")]
public class Connect : Object,
Extensibility.IDTExtensibility2
{
public Outlook.TaskItemClass
outlookItems ;
private Outlook.Application
applicationObject;
private object addInInstance;


public Connect()
{
}


public void OnConnection(object
application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject =
(Outlook.Application)application;
addInInstance = addInInst;

if (connectMode !=
Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref
custom);
}
MessageBox.Show("Connected1");
register();
}

public void register()
{
Outlook.NameSpace ns =

applicationObject.GetNamespace("MAPI");

Outlook.MAPIFolder TaskFolder =
ns.GetDefaultFolder

(Outlook.OlDefaultFolders.olFolderTasks);
TaskFolder.Items.ItemChange +=new
Outlook.ItemsEvents_ItemChangeEventHandler
(Items_ItemChange);


applicationObject.Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler
(Inspectors_NewInspector);

}
private void Connect_Open(ref bool Cancel)
{
MessageBox.Show("Connect_Open");

}

public void OnDisconnection
(Extensibility.ext_DisconnectMode disconnectMode, ref
System.Array custom)
{
MessageBox.Show("Disconnected");
if(disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref
custom);
}
applicationObject = null;

}

public void OnAddInsUpdate(ref
System.Array custom)
{
}

public void OnStartupComplete(ref
System.Array custom)
{
}

public void OnBeginShutdown(ref
System.Array custom)
{
}

private void Connect_FolderSwitch()
{

}

private void Items_ItemChange(object Item)
{
MessageBox.Show("Change");
}


private void Connect_ItemEvents_Event_Open
(ref bool Cancel)
{
MessageBox.Show
("Connect_ItemEvents_Event_Open");
try
{
string val=
ConfigurationSettings.AppSettings["myVal"];
}
catch(Exception ex)
{
throw ex;
}
Cancel = true;
}

private void Inspectors_NewInspector
(Outlook.Inspector Inspector)
{

outlookItems =
(Outlook.TaskItemClass)(Inspector.CurrentItem);
if (Inspector.CurrentItem is
Outlook.TaskItemClass)
{
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).ItemEvents_Event_Open +=new
Outlook.ItemEvents_OpenEventHandler
(Connect_ItemEvents_Event_Open);
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).Open+=new
Outlook.ItemEvents_10_OpenEventHandler(Connect_Open);
}
}

}
}


.
 
applicationObject.Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);

is the same as

tempinpectors = applicationObject.Inspectors
tempinpectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);

where tempinpectors is an implicit local temporary variable created by the
compiler. Once it is released (which does not happen immediately due to the
GC), you will no longer get any events.

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


Thank You Dmitry !!!
that was it.

I would greatly appreciate if you can explain what was the
problem, or give any links to information regarding this
issue.

Again, many thanks.

Ilan
-----Original Message-----
Store the inspectors collection as a class variable and change your code to

m_Inspectors = applicationObject.Inspectors;
m_Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler (Inspectors_NewInspector);

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


ilan said:
Hi,

I'm catching the event of opening a task.

in the event handler I'm accessing a config file (I
created Outlook.exe.config in the C:\Program
Files\Microsoft Office\OFFICE11 folder and added "MyVal"
value to it)
I'm getting the correct value from my config file but
it only happens once. The NewInspector event won't fire
again.

Ommiting the line that access the config file results with
this event fires normally.

Any suggestions?

I'm using Outlook 2003 win 2003.

This is the code I use:
namespace MyFirstOutlookAddin
{

using System;
using Microsoft.Office.Core;
using System.Windows.Forms;
using System.Reflection;
using Extensibility;
using System.Runtime.InteropServices;
using System.Configuration;
using System.IO;

[GuidAttribute("EADFD989-C91D-4E2C-9D76-
5DA414736ECD"), ProgId("MyFirstOutlookAddin.Connect")]
public class Connect : Object,
Extensibility.IDTExtensibility2
{
public Outlook.TaskItemClass
outlookItems ;
private Outlook.Application
applicationObject;
private object addInInstance;


public Connect()
{
}


public void OnConnection(object
application, Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject =
(Outlook.Application)application;
addInInstance = addInInst;

if (connectMode !=
Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref
custom);
}
MessageBox.Show("Connected1");
register();
}

public void register()
{
Outlook.NameSpace ns =

applicationObject.GetNamespace("MAPI");

Outlook.MAPIFolder TaskFolder =
ns.GetDefaultFolder

(Outlook.OlDefaultFolders.olFolderTasks);
TaskFolder.Items.ItemChange +=new
Outlook.ItemsEvents_ItemChangeEventHandler
(Items_ItemChange);


applicationObject.Inspectors.NewInspector +=new
Outlook.InspectorsEvents_NewInspectorEventHandler
(Inspectors_NewInspector);

}
private void Connect_Open(ref bool Cancel)
{
MessageBox.Show("Connect_Open");

}

public void OnDisconnection
(Extensibility.ext_DisconnectMode disconnectMode, ref
System.Array custom)
{
MessageBox.Show("Disconnected");
if(disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref
custom);
}
applicationObject = null;

}

public void OnAddInsUpdate(ref
System.Array custom)
{
}

public void OnStartupComplete(ref
System.Array custom)
{
}

public void OnBeginShutdown(ref
System.Array custom)
{
}

private void Connect_FolderSwitch()
{

}

private void Items_ItemChange(object Item)
{
MessageBox.Show("Change");
}


private void Connect_ItemEvents_Event_Open
(ref bool Cancel)
{
MessageBox.Show
("Connect_ItemEvents_Event_Open");
try
{
string val=
ConfigurationSettings.AppSettings["myVal"];
}
catch(Exception ex)
{
throw ex;
}
Cancel = true;
}

private void Inspectors_NewInspector
(Outlook.Inspector Inspector)
{

outlookItems =
(Outlook.TaskItemClass)(Inspector.CurrentItem);
if (Inspector.CurrentItem is
Outlook.TaskItemClass)
{
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).ItemEvents_Event_Open +=new
Outlook.ItemEvents_OpenEventHandler
(Connect_ItemEvents_Event_Open);
((Outlook.TaskItemClass)
(Inspector.CurrentItem)).Open+=new
Outlook.ItemEvents_10_OpenEventHandler(Connect_Open);
}
}

}
}


.
 
Back
Top