Commit e06f51f9 张东亮

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

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