본문 바로가기

C#35

[C#] 오류를 파일에 기록해보자! using System; using System.IO; namespace TEST { public class Program { public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { File.WriteAllText("exception.txt", e.ExceptionObject.ToString()); } } } 한 줄이면 딱 끝나. 이게 AppDomain.Curren.. 2023. 2. 21.
곰녹음기를 죽이는 방법 저장하기에 aux 넣고 저장 누르면 죽는다. 2023. 2. 19.
[C# WPF] Binding Binding이란? WPF에서 쓸 수 있는 기술이다. 쓰는 방법은 무척 간단하다. 큰 따옴표 안에 {Binding}을 써 주기만 하면 끝이다. Binding을 사용할 수 있는 가장 단순하고 쉬운 방법은 ElementName을 지정한 후 그 Element의 속성을 Path로 지정해주는 것이다. 실제로 저 프로그램을 실행해보면... 프로그램 창의 Title이 ActualWidth와 실시간으로 동기화되는 것을 볼 수 있다. 2023. 2. 18.
mciSendString 음질 개선 https://stackoverflow.com/a/3694293 How do I record audio with C#/WPF? I have an application to which I want to add the ability to import small audio snippets directly from a microphone device of some sort. I already allow importing of pictures and this works okay with stackoverflow.com C#으로 목소리 녹음을 하는 방법 중 하나는 mciSendString이다. 답변에도 나와있듯이 엄청 간단하다. open, record, save 이 세 가지가 끝이다. 근데 결과물을 들으면 음질이 .. 2023. 2. 3.
[C# WPF] super mario 63의 cheat를 구현해 보자. super mario 63에는 "cheat"를 입력하면 모든 것을 잠금 해제할 수 있는 창이 나온다. wpf에서도 창에 cheat를 입력하면 이벤트가 발생하도록 할 수 있을까? using System.Windows; using System.Windows.Input; namespace cheat { public partial class MainWindow : Window { private int cheatIndex = 0; private Key[] cheatKeys = {Key.C, Key.H,Key.E,Key.A,Key.T}; public MainWindow() { InitializeComponent(); } protected override void OnKeyDown(KeyEventArgs e) { b.. 2023. 2. 3.
[C# WPF] 연속해서 여러 번 클릭하는 것을 방지해보자. 다음과 같은 코드가 있다. public partial class MainWindow : Window { private void Button_Click(object sender, RoutedEventArgs e) { Thread.Sleep(500); Title += "a"; } } Title을 수정하는 코드가 0초가 걸린다고 하면 이 버튼은 클릭을 할 때마다 0.5초가 걸리는 작업을 한다. 근데 클릭을 한 번 하고 나서 0.5초의 작업을 하는 동안 한 번 더 클릭하면 클릭이 예약이 되어버린다. 버튼을 눌렀더니 0.5초 동안 무응답이길래 한 번 더 눌렀는데 1초를 기다려야 하는 셈이다. 성질 급한 사람은 3번 이상 누를지도 모른다. 그럼 무응답인 시간은 계속 길어지고, 스트레스는 증가하고, 버튼은 계속 누르.. 2023. 1. 20.
[C#] StackOverflowException은 얼마나 스택이 쌓여야 뜰까? class Program { static void Main(string[] args) { a(0); } private static void a(int b) { Console.WriteLine(b); a(b + 1); } } 15138 15139 15140 15141 15142 15143 15144 15145 15146 15147 15148 15149 15150 15151 15152 15153 Process is terminated due to StackOverflowException. Press any key to continue . . . 15155개의 스택이 쌓이면 오류가 뜸을 알 수 있다. 2023. 1. 13.
[C#] Tesseract.Page의 메소드별 경과 시간 비교 class Program { static void Main(string[] args) { var pix = Pix.LoadFromFile("file path"); using (var engine = new TesseractEngine(".", "eng")) { engine.SetVariable("thresholding_method", 2); engine.SetVariable("load_system_dawg", false); engine.SetVariable("load_freq_dawg", false); var page = engine.Process(pix); var watch = Stopwatch.StartNew(); // code from here page.GetAltoText(0); // to her.. 2023. 1. 11.
[C#] Property의 StackOverflow public ImageSource Icon { get { return Icon; } set { if(value != Icon) { Icon = value; OnPropertyChanged("Icon"); } } } 위와 같은 Property를 넣고 프로그램을 디버그하니까 Process is terminated due to StackOverflowException. 라는 메시지가 나왔다. 왜 그런걸까? 문제의 코드는 무려 두 군데나 있었다. 첫 번째는 get에서 return Icon, 두 번째는 set에서 Icon = value다. 두 코드 모두 get과 set을 재귀적으로 호출하게 된다. 결국 끝나지 않는 무한루프에 빠지게 되는 것이다. private ImageSource icon; public Imag.. 2023. 1. 10.
[C# WPF] Ctrl Z 감지하기 private void Window_KeyDown(object sender, KeyEventArgs e) { if(e.Key==Key.Z && e.KeyboardDevice.Modifiers == ModifierKeys.Control) { Console.WriteLine("wow"); } } 실험해본 결과 Z를 먼저 누르고 Control을 누르면 wow가 출력되지 않는다. 2023. 1. 9.