Commit e06f51f9 张东亮

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

1 个父辈 52918c31
...@@ -39,67 +39,51 @@ namespace OnlineStore.Common ...@@ -39,67 +39,51 @@ 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; string res = "";
decimal a = 0; if (Monitor.TryEnter(lockobj, 500))
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetNumValue(keyStr);
}
else
{ {
try
{ {
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a); Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
}
else
{
res= config.AppSettings.Settings[key].Value;
}
} }
} finally
return a;
}
public static int GetIntValue(string keyStr, string storeStr)
{
string key = keyStr + storeStr;
int a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetIntValue(keyStr);
}
else
{
{ {
Int32.TryParse(config.AppSettings.Settings[key].Value, out a); Monitor.Exit(lockobj);
} }
} return a;
}
public static string GetValue(string key)
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
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;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (Monitor.TryEnter(lockobj, 500))
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return a;
}
else
{ {
try
{ {
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a); System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
}
else
{
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
finally
{
Monitor.Exit(lockobj);
} }
} }
return a; return a;
...@@ -107,18 +91,26 @@ namespace OnlineStore.Common ...@@ -107,18 +91,26 @@ namespace OnlineStore.Common
public static int GetIntValue(string key) public static int GetIntValue(string key)
{ {
int a = 0; int a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (Monitor.TryEnter(lockobj, 500))
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return a;
}
else
{ {
try
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
}
else
{
Int32.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
finally
{ {
Int32.TryParse(config.AppSettings.Settings[key].Value, out a); Monitor.Exit(lockobj);
} }
} return a; }
return a;
} }
public static void SaveValue(string key, int value) public static void SaveValue(string key, int value)
{ {
...@@ -150,8 +142,8 @@ namespace OnlineStore.Common ...@@ -150,8 +142,8 @@ namespace OnlineStore.Common
{ {
LogUtil.error("SaveValue保存配置出错:AppKey=" + key + ",AppValue=" + value + ",", ex); LogUtil.error("SaveValue保存配置出错:AppKey=" + key + ",AppValue=" + value + ",", ex);
} }
finally finally
{ {
Monitor.Exit(lockobj); Monitor.Exit(lockobj);
} }
} }
...@@ -181,10 +173,10 @@ namespace OnlineStore.Common ...@@ -181,10 +173,10 @@ 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);
} }
} }
///<summary> ///<summary>
///向.config文件的appKey结写入信息AppValue 保存设置 ///向.config文件的appKey结写入信息AppValue 保存设置
...@@ -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!