본문 바로가기

C#(CSharp)71

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.
Write exception log in File. private static void writeExceptionLog(Exception ex) { try { string curPath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string filePath = curPath + "\\exceptionLog.log"; using (StreamWriter writer = new StreamWriter(filePath, true)) { writer.WriteLine("Message :" + ex.Message + " " + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Da.. 2018. 5. 29.
c# memory cache private void btnGet_Click(object sender, EventArgs e) { ObjectCache cache = MemoryCache.Default; string fileContents = cache["filecontents"] as string; if (fileContents == null) { CacheItemPolicy policy = new CacheItemPolicy(); List filePaths = new List(); filePaths.Add("c:\\cache\\example.txt"); policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); // Fetch the file contents. fileCon.. 2018. 5. 26.
Deleting multiple files with wildcard var dir = new DirectoryInfo(directoryPath); foreach (var file in dir.EnumerateFiles("f*.txt")) { file.Delete(); }SOURCE : https://stackoverflow.com/questions/8807209/deleting-multiple-files-with-wildcard?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa 2018. 5. 17.