private static void EnsureAppIdInited() { if (s_appId == null) { IApplicationIdentifier ai = null; IServiceProvider host = ObjectCache.Host; if (host != null) { ai = host.GetService(typeof(IApplicationIdentifier)) as IApplicationIdentifier; } // if the host has an identifier, use it string appId = (ai != null) ? ai.GetApplicationId() : null; // otherwise, use the process name wihtout file extension if (String.IsNullOrEmpty(appId)) { StringBuilder sb = new StringBuilder(512); if (UnsafeNativeMethods.GetModuleFileName(IntPtr.Zero, sb, 512) != 0) { appId = Path.GetFileNameWithoutExtension(sb.ToString()); } } // if all else fails, use AppDomain.FriendlyName if (String.IsNullOrEmpty(appId)) { appId = AppDomain.CurrentDomain.FriendlyName; } Interlocked.CompareExchange(ref s_appId, appId, null); } }
private static void EnsureAppIdInited() { if (s_appId == null) { IApplicationIdentifier service = null; IServiceProvider host = ObjectCache.Host; if (host != null) { service = host.GetService(typeof(IApplicationIdentifier)) as IApplicationIdentifier; } string fileNameWithoutExtension = (service != null) ? service.GetApplicationId() : null; if (string.IsNullOrEmpty(fileNameWithoutExtension)) { StringBuilder filename = new StringBuilder(0x200); if (System.Runtime.Caching.UnsafeNativeMethods.GetModuleFileName(IntPtr.Zero, filename, 0x200) != 0) { fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filename.ToString()); } } if (string.IsNullOrEmpty(fileNameWithoutExtension)) { fileNameWithoutExtension = AppDomain.CurrentDomain.FriendlyName; } Interlocked.CompareExchange <string>(ref s_appId, fileNameWithoutExtension, null); } }