共享办公室插件中静态 class 或变量的范围
Scope of static class or variable in Shared office Addin
我们在共享插件(Word、Outlook)中有一个静态映射,用于在应用程序运行时存储一些缓存信息,如下所示:
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
}
}
我们有一个用例,我们使用 Outlook 发送邮件并对邮件发送执行如下操作:
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_ItemSend() 中,当我尝试获取 GlobalMap 时 returns 空。据我所知,静态变量可以跨线程访问。
是因为应用程序间通信吗?为什么当我尝试访问 GlobalMap return null 时?
如有任何帮助,我将不胜感激
COM 插件实现为每个主机进程加载的 dll(outlook.exe、msword.exe 等)。没有 类 在两个 运行 进程之间共享。你需要想出一个不同的存储机制(注册表?文件系统?)来共享公共数据。
我们在共享插件(Word、Outlook)中有一个静态映射,用于在应用程序运行时存储一些缓存信息,如下所示:
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
}
}
我们有一个用例,我们使用 Outlook 发送邮件并对邮件发送执行如下操作:
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_ItemSend() 中,当我尝试获取 GlobalMap 时 returns 空。据我所知,静态变量可以跨线程访问。 是因为应用程序间通信吗?为什么当我尝试访问 GlobalMap return null 时?
如有任何帮助,我将不胜感激
COM 插件实现为每个主机进程加载的 dll(outlook.exe、msword.exe 等)。没有 类 在两个 运行 进程之间共享。你需要想出一个不同的存储机制(注册表?文件系统?)来共享公共数据。