private static void Initialize() { TokenDictionary.WriteLine(AppDomain.CurrentDomain.FriendlyName); initializing = true; var host = new mscoree.CorRuntimeHost(); object defaultAppDomain; host.GetDefaultDomain(out defaultAppDomain); AppDomain defAppDomain = (AppDomain)defaultAppDomain; defAppDomain.DoCallBack(new CrossAppDomainDelegate(InitializeFromWrapper)); initializing = false; }
internal static void InitializeFromWrapper() { TokenDictionary.WriteLine(AppDomain.CurrentDomain.FriendlyName); if (!initialized) { initThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; tokenDic = new MyConcurrentDictionary <string, TokenInfo>(); TokenDictionary.WriteLine("Dictionary Initialized, threadId:{0}", initThreadId); localTimer = new System.Timers.Timer(10000); localTimer.Elapsed += LocalTimer_Elapsed; //GC.SuppressFinalize(tokenDic); //GC.SuppressFinalize(localTimer); initialized = true; } }
private static void LocalTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { TokenDictionary.WriteLine("Timer, Dic Count: {0}", tokenDic.Count); var keys = tokenDic.Keys.ToList(); foreach (string key in keys) { TokenInfo ti = tokenDic[key]; if (!ti.IsValid & !ti.IsWaiting) { tokenDic.TryRemove(key, out ti); } } if (tokenDic.Count == 0) { localTimer.Enabled = false; TokenDictionary.WriteLine("Timer is disabled"); WriteLogMessage("No more valid token available in the dictionary"); } }