public void Write(String msg, params Object[] args) { FResourceLock.EnterWriteLock(); try { using (TextWriter tw = OpenFileStream()) { tw.WriteLine(msg, args); } } finally { FResourceLock.ExitWriteLock(); } }
/// <summary> /// Gets the specified name. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name">The name.</param> /// <param name="bSlidingTimeWindow">if set to <c>true</c> [b sliding time window].</param> /// <param name="callback">The callback.</param> /// <param name="args">The arguments.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">callback</exception> public T Get <T>(string name, bool bSlidingTimeWindow, Func <string, object[], CacheDataInfo <T> > callback = null, params object[] args) { var node = GetCachedNode(name, bSlidingTimeWindow); if (node == null) { if (callback == null) { return(default(T)); } using (var rLock = new ResourceLock(name)) { rLock.EnterWriteLock(); try { node = GetCachedNode(name, bSlidingTimeWindow); if (node == null) { var cData = callback(name, args); if (cData == null) { return(default(T)); } Set(name, cData.NewCacheData, cData.KeepAlive); return(cData.NewCacheData); } } finally { rLock.ExitWriteLock(); } } } return((T)node.Data); }