Commit e06f51f9 张东亮

appconfig读取与写入冲突问题修复,加锁

1 个父辈 52918c31
......@@ -39,86 +39,78 @@ namespace OnlineStore.Common
return config.AppSettings.Settings[key].Value;
}
}
public static decimal GetNumValue(string keyStr, string storeStr)
{
string key = keyStr + storeStr;
decimal a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetNumValue(keyStr);
}
else
public static string GetValue(string key)
{
string res = "";
if (Monitor.TryEnter(lockobj, 500))
{
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
return a;
}
public static int GetIntValue(string keyStr, string storeStr)
try
{
string key = keyStr + storeStr;
int a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetIntValue(keyStr);
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
}
else
{
{
Int32.TryParse(config.AppSettings.Settings[key].Value, out a);
res= config.AppSettings.Settings[key].Value;
}
} return a;
}
public static string GetValue(string key)
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
finally
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return "";
Monitor.Exit(lockobj);
}
else
{
return config.AppSettings.Settings[key].Value;
}
return res;
}
public static decimal GetNumValue(string key)
{
decimal a = 0;
if (Monitor.TryEnter(lockobj, 500))
{
try
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return a;
}
else
{
{
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
finally
{
Monitor.Exit(lockobj);
}
}
return a;
}
public static int GetIntValue(string key)
{
int a = 0;
if (Monitor.TryEnter(lockobj, 500))
{
try
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return a;
}
else
{
{
Int32.TryParse(config.AppSettings.Settings[key].Value, out a);
}
} return a;
}
finally
{
Monitor.Exit(lockobj);
}
}
return a;
}
public static void SaveValue(string key, int value)
{
......@@ -181,7 +173,7 @@ namespace OnlineStore.Common
}
catch (Exception ex)
{
LogUtil.error( "UpdateConfig保存配置出错:name=" + name + ",Xvalue=" + Xvalue + ",",ex);
LogUtil.error("UpdateConfig保存配置出错:name=" + name + ",Xvalue=" + Xvalue + ",", ex);
}
}
......@@ -215,7 +207,7 @@ namespace OnlineStore.Common
}
catch (Exception ex)
{
LogUtil.error( "SetValue保存配置出错:AppKey=" + AppKey + ",AppValue=" + AppValue + ",",ex);
LogUtil.error("SetValue保存配置出错:AppKey=" + AppKey + ",AppValue=" + AppValue + ",", ex);
}
}
}
......
......@@ -332,12 +332,11 @@ namespace OnlineStore.DeviceLibrary
}
return false;
}
bool isScan = ConfigAppSettings.GetIntValue(Setting_Init.NeedScanCode).Equals(1);
private void IB11_ScanCode()
{
ClearWarnMsg("等待旋转轴离开料串超时");
MoveInfo.NextMoveStep(StepEnum.IB11_ScanCode);
bool isScan = ConfigAppSettings.GetIntValue(Setting_Init.NeedScanCode).Equals(1);
LastCodeList = new List<string>();
//if (NextCodeList.Count > 0)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!