Commit e06f51f9 张东亮

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

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