C# 共享office加载项中静态类或变量的作用域
我们在共享加载项(Word,Outlook)中有一个静态映射,用于在应用程序运行时存储一些缓存信息,如下所示:C# 共享office加载项中静态类或变量的作用域,c#,outlook,vsto,outlook-addin,word-addins,C#,Outlook,Vsto,Outlook Addin,Word Addins,我们在共享加载项(Word,Outlook)中有一个静态映射,用于在应用程序运行时存储一些缓存信息,如下所示: public static class GlobalVariables { //Key constants public static string USER_ACTION = "userAction"; //private methods private static Dictionary<string, Object> globalMa
public static class GlobalVariables
{
//Key constants
public static string USER_ACTION = "userAction";
//private methods
private static Dictionary<string, Object> globalMap = new Dictionary<string, object>();
public static Dictionary<string, Object> GlobalMap
{
set { globalMap = value; }
get { return globalMap; }
}
public static Object get(string key)
{
// custom Implementation
}
public static void Add(string key, Object obj)
{
//custom implementation
}
}
private void adxOutlookAppEvents_ItemSend(object sender, ADXOlItemSendEventArgs e)
{
try
{
Outlook._MailItem mailItem = e.Item as Outlook._MailItem;
string action = (string)GlobalVariables.get(GlobalVariables.USER_ACTION);
if (false == string.IsNullOrEmpty(action))
{
this.performUserActionAfterMailSend(action);
}
catch (CustomeMessageException ex)
{
CommonUtils.iAlert(ex.Message);
}
catch (Exception ex)
{
CommonUtils.iError(RESOURCE.COMMON_ERROR_MSG);
}
finally
{
//CommonUtils.releaseComObject(oRecips);
}
}
但是在adxOutlookAppEvents\u ItemSend()中,当我尝试获取GlobalMap时,它返回null。据我所知,静态变量可以跨线程访问。
是因为应用程序间通信吗?当我尝试访问GlobalMap时,为什么返回null
如果您能提供任何帮助,我将不胜感激。COM加载项将作为DLL由每个主机进程(outlook.exe、msword.exe等)加载。两个正在运行的进程之间从未共享任何类。您需要使用不同的存储机制(注册表?文件系统?)来共享公共数据。感谢您的回复,是否可以向Outlook邮件项目(Microsoft.Office.Interop.Outlook.\u MailItem)添加自定义属性,以便我可以识别特定的Outlook项目?当然,请使用MailItem.UserProperties集合。请记住,发送带有用户属性的邮件可能会强制Outlook以RTF格式(臭名昭著的winmal.dat)发送。您还可以使用MailItem.PropertyAccessor通过DASL名称读取/写入自定义命名属性。。使用OutlookSpy()查看项目-单击IMessage按钮在MAPI级别上播放属性。