我们在共享插件(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时,它返回null。据我所知,静态变量可以跨线程访问。是因为应用程序间通信吗?为什么当我尝试访问 GlobalMap 时返回 null?
我将不胜感激任何帮助