본문 바로가기

C#4

C# winform 구성 시스템을 초기화하지 못했습니다. 에러 해결방법 C:\Users\user\AppData\Local\프로그램이름\프로그램이름\버전 폴더로 들어가 ~~.config 파일을 삭제해주고 실행하면 해결된다. 해당 에러는 여러 원인이 있겠지만 로그에 Xml 위주의 에러가 써있다면 시도해볼만하다. 2023. 1. 18.
C# rundll32 으로 이미지 프린트 하기 1 2 3 4 5 6 7 8 using (System.Diagnostics.Process process = new System.Diagnostics.Process()) { string printerName = "Printer Name"; process.StartInfo.FileName = "rundll32"; process.StartInfo.Arguments = @"C:\WINDOWS\system32\shimgvw.dll,ImageView_PrintTo """ + ImagePath + @""" " + @"""" + printerName + @""""; process.StartInfo.UseShellExecute = true; process.Start(); } Colored by Color Scripter.. 2022. 11. 16.
C# 폴더에서 특정 확장자만 가져와서 시간순으로 정렬 후 10개만 가져오는 코드 (Linq) var list = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".png") || s.EndsWith(".jpg")) .OrderByDescending(d => new FileInfo(d).CreationTime) .Take(10).ToArray(); path에서 .Where(s => s.EndsWith(".png") || s.EndsWith(".jpg")) png랑 jpg를 가져온다음 .OrderByDescending(d => new FileInfo(d).CreationTime) 최신순으로 정렬 후 .Take(10) 그중 10개까지만 가져와 .ToArray() 배열로 만든다. 성능은 모.. 2022. 7. 26.
c# 멀티쓰레드 SpinLock 구현 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 class SpinLock { volatile int locked = 0; public void Acquire() { while (true) { int expected = 0; int desired = 1; if (Interlocked.CompareExchange(ref locked, desired, expected) == expected) break; } } public void Release().. 2022. 4. 17.