본문 바로가기

C#(CSharp)/Etc31

Single Global Mutex I want to make sure this is out there, because it's so hard to get right: using System.Runtime.InteropServices; //GuidAttribute using System.Reflection; //Assembly using System.Threading; //Mutex using System.Security.AccessControl; //MutexAccessRule using System.Security.Principal; //SecurityIdentifier static void Main(string[] args) { // get application GUID as defined in AssemblyInfo.cs strin.. 2019. 6. 25.
Easily write a whole class instance to XML File and read back in Code snippet to serialize your garage to file could look like:var garage = new theGarage(); // TODO init your garage.. XmlSerializer xs = new XmlSerializer(typeof(theGarage)); TextWriter tw = new StreamWriter(@"c:\temp\garage.xml"); xs.Serialize(tw, garage);And code to load garage from file:using(var sr = new StreamReader(@"c:\temp\garage.xml")) { garage = (theGarage)xs.Deserialize(sr); } SOURCE.. 2018. 6. 25.
IOException: The process cannot access the file 'file path' because it is being used by another process private const int NumberOfRetries = 3; private const int DelayOnRetry = 1000; for (int i=1; i 2018. 6. 23.
C# memory cache logic Here is the way that I've done it in the past: private static string _key = "foo"; private static readonly MemoryCache _cache = MemoryCache.Default; //Store Stuff in the cache public static void StoreItemsInCache() { List itemsToAdd = new List(); //Do what you need to do here. Database Interaction, Serialization,etc. var cacheItemPolicy = new CacheItemPolicy() { //Set your Cache expiration. Abso.. 2018. 5. 31.