mirror of
https://github.com/KevinWG/OSS.Common.git
synced 2026-10-28 13:50:52 +08:00
底层线程安全处理
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace OS.Common.Modules.AsynModule
|
||||
{
|
||||
@@ -8,7 +8,7 @@ namespace OS.Common.Modules.AsynModule
|
||||
/// </summary>
|
||||
public static class AsynUtil
|
||||
{
|
||||
private static IDictionary<string, IAsynBlock> _asynDirs = new Dictionary<string, IAsynBlock>();
|
||||
private static readonly ConcurrentDictionary<string, IAsynBlock> _asynDirs = new ConcurrentDictionary<string, IAsynBlock>();//Dictionary<string, IAsynBlock>();
|
||||
/// <summary>
|
||||
/// 通过模块名称获取异步处理模块实例
|
||||
/// </summary>
|
||||
@@ -21,11 +21,10 @@ namespace OS.Common.Modules.AsynModule
|
||||
|
||||
if (_asynDirs.ContainsKey(asynModule))
|
||||
return _asynDirs[asynModule];
|
||||
|
||||
|
||||
var asyn = OsConfig.Provider.GetAsynBlock(asynModule) ?? new AsynBlock();
|
||||
_asynDirs.Add(asynModule, asyn);
|
||||
|
||||
_asynDirs.TryAdd(asynModule,asyn);
|
||||
|
||||
return asyn;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OS.Common.Modules.CacheModule
|
||||
@@ -8,7 +9,7 @@ namespace OS.Common.Modules.CacheModule
|
||||
/// </summary>
|
||||
public static class CacheUtil
|
||||
{
|
||||
private static IDictionary<string ,ICache> _cacheDirs=new Dictionary<string, ICache>();
|
||||
private static readonly ConcurrentDictionary<string, ICache> _cacheDirs = new ConcurrentDictionary<string, ICache>();
|
||||
|
||||
/// <summary>
|
||||
/// 通过模块名称获取
|
||||
@@ -24,7 +25,7 @@ namespace OS.Common.Modules.CacheModule
|
||||
return _cacheDirs[cacheModule];
|
||||
|
||||
var cache = OsConfig.Provider.GetCache(cacheModule) ?? new Cache();
|
||||
_cacheDirs.Add(cacheModule, cache);
|
||||
_cacheDirs.TryAdd(cacheModule, cache);
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using OS.Common.ComModels;
|
||||
|
||||
namespace OS.Common.Modules.DirConfigModule
|
||||
@@ -8,7 +8,7 @@ namespace OS.Common.Modules.DirConfigModule
|
||||
/// </summary>
|
||||
public static class DirConfigUtil
|
||||
{
|
||||
private static IDictionary<string, IDirConfig> _dirConfigDirs = new Dictionary<string, IDirConfig>();
|
||||
private static readonly ConcurrentDictionary<string, IDirConfig> _dirConfigDirs = new ConcurrentDictionary<string, IDirConfig>();
|
||||
|
||||
/// <summary>
|
||||
/// 通过模块名称获取
|
||||
@@ -24,7 +24,7 @@ namespace OS.Common.Modules.DirConfigModule
|
||||
return _dirConfigDirs[dirConfigModule];
|
||||
|
||||
var dirConfig = OsConfig.Provider.GetDirConfig(dirConfigModule) ?? new DirConfig();
|
||||
_dirConfigDirs.Add(dirConfigModule, dirConfig);
|
||||
_dirConfigDirs.TryAdd(dirConfigModule, dirConfig);
|
||||
|
||||
return dirConfig;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using OS.Common.Modules.AsynModule;
|
||||
|
||||
@@ -98,12 +99,10 @@ namespace OS.Common.Modules.LogModule
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
private static Dictionary<string, ILogWriter> _logDirs=
|
||||
new Dictionary<string, ILogWriter>();
|
||||
|
||||
|
||||
private static readonly ConcurrentDictionary<string, ILogWriter> _logDirs =
|
||||
new ConcurrentDictionary<string, ILogWriter>();
|
||||
|
||||
/// <summary>
|
||||
/// 通过模块名称获取日志模块实例
|
||||
/// </summary>
|
||||
@@ -118,7 +117,7 @@ namespace OS.Common.Modules.LogModule
|
||||
return _logDirs[logModule];
|
||||
|
||||
var log = OsConfig.Provider.GetLogWrite(logModule) ?? new LogWriter();
|
||||
_logDirs.Add(logModule, log);
|
||||
_logDirs.TryAdd(logModule, log);
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace OS.Common.Modules.LogModule
|
||||
internal class LogWriter : ILogWriter
|
||||
{
|
||||
private readonly string _logBaseDirPath = null;
|
||||
private const string logFormat = "{0:T} Key:{1} Detail:{2}";
|
||||
private const string _logFormat = "{0:T} Key:{1} Detail:{2}";
|
||||
|
||||
public LogWriter()
|
||||
{
|
||||
@@ -39,7 +39,8 @@ namespace OS.Common.Modules.LogModule
|
||||
|
||||
using (StreamWriter sw = new StreamWriter(filePath, true, Encoding.Default))
|
||||
{
|
||||
sw.WriteLine(format: logFormat, arg0: DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), arg1: info.MsgKey, arg2: info.Msg);
|
||||
// ReSharper disable once FormatStringProblem
|
||||
sw.WriteLine(format: _logFormat, arg0: DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), arg1: info.MsgKey, arg2: info.Msg);
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OS.Common</RootNamespace>
|
||||
<AssemblyName>OS.Common</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace OS.Common
|
||||
/// </summary>
|
||||
internal static ModuleBaseProvider Provider
|
||||
{
|
||||
get { return _provider ?? new ModuleBaseProvider(); }
|
||||
get { return _provider ?? (_provider = new ModuleBaseProvider()); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
@@ -32,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.17.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.17.0")]
|
||||
[assembly: AssemblyVersion("1.2.35.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.35.0")]
|
||||
|
||||
Reference in New Issue
Block a user