부모글 보이기/감추기 AD BLOCK 해제 요청 이 글에는 광고가 많이 들어가 있지 않습니다. adblock을 해제하셔도 글을 읽는데 그다지 부담이 없으니 해제를 부탁드립니다. (연관된 글이 1개 있습니다.) C# 9 최상위 문에 STAThread 사용 아래와 같은 질문이 있군요, ^^ C# Top-level Statements WPF 실행 방법? ; https://forum.dotnetdev.kr/t/c-top-level-statements-wpf/799 결론 먼저 말하자면, 최상위 문(Top Level Statement)에서는, C# 9.0 - (15) 최상위 문(Top-level statements) ; https://www.sysnet.pe.kr/2/0/12406 자동 생성되는 <Main>$ 메서드에 대해 특성(Attribute)을 부여할 수 없습니다. (향후 지원할지는 모르겠지만!) 그래서 어쩔 수 없이 Thread에 Apartment를 직접 설정해 사용해야만 합니다. 이에 대해서는 이미 다음의 글 들에서 잘 다루고 있는데요, How to handle [STAThread] in C# 9 Using Top-Level Program.cs ; https://stackoverflow.com/questions/64946371/how-to-handle-stathread-in-c-sharp-9-using-top-level-program-cs Set ApartmentState on a Task ; https://stackoverflow.com/questions/16720496/set-apartmentstate-on-a-task using System; using System.Threading; using System.Threading.Tasks; using System.Windows; await StartSTATask(() => { Application app = new Application(); app.Startup += (s, e) => new Window().Show(); app.Run(); return 0; }); static Task<T> StartSTATask<T>(Func<T> func) { var tcs = new TaskCompletionSource<T>(); Thread thread = new Thread(() => { try { tcs.SetResult(func()); } catch (Exception e) { tcs.SetException(e); } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); return tcs.Task; } [이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.] [다음 글] .NET Framework: 1055. C# - struct/class가 스택/힙에 할당되는 사례 정리[이전 글] 오류 유형: 713. XSD 파일을 포함한 프로젝트 - The type or namespace name 'TypedTableBase<>' does not exist in the namespace 'System.Data' [연관 글] 오류 유형: 714. error CS5001: Program does not contain a static 'Main' method suitable for an entry point [최초 등록일: 5/2/2021] [최종 수정일: 5/2/2021] 이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다. by SeongTae Jeong, mailto:techsharer at outlook.com 비밀번호 댓글 작성자 2021-10-05 10시19분 현재 이 글에 쓰인 방법 이외에, 그냥 단순하게 프로그램 초기에 다음과 같이 코딩하시면 됩니다.Thread.CurrentThread.SetApartmentState(ApartmentState.Unknown);Thread.CurrentThread.SetApartmentState(ApartmentState.STA);(확인은 안 했지만) 아마도 Unknown 옵션을 주는 경우 CoUninitialize를 호출하는 것이 아닐까... 예상해 봅니다. ^^ 정성태 ... 106 107 108 109 110 111 [112] 113 114 115 116 117 118 119 120 ... NoWriterDateCnt.TitleFile(s) 11216정성태6/1/201721342오류 유형: 396. Activation context generation failed11215정성태6/1/201724214오류 유형: 395. 관리 콘솔을 실행하면 "This app has been blocked for your protection" 오류 발생 [1]11214정성태6/1/201720995오류 유형: 394. MSDTC 서비스 시작 시 -1073737712(0xC0001010) 오류와 함께 종료되는 문제 [1]11213정성태5/26/201727214오류 유형: 393. TFS - The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.11212정성태5/26/201726525오류 유형: 392. Windows Server 2016에 KB4019472 업데이트가 실패하는 경우11211정성태5/26/201724904오류 유형: 391. BeginInvoke에 전달한 람다 함수에 CS1660 에러가 발생하는 경우11210정성태5/25/201725051기타: 65. ActiveX 없는 전자 메일에 사용된 "개인정보 보호를 위해 암호화된 보안메일"의 암호화 방법11209정성태5/25/201774237Windows: 143. Windows 10의 Recovery 파티션을 삭제 및 새로 생성하는 방법 [16]11208정성태5/25/201731129오류 유형: 390. diskpart의 set id 명령어에서 "The specified type is not in the correct format." 오류 발생11207정성태5/24/201733125Windows: 142. Windows 10의 복구 콘솔로 부팅하는 방법11206정성태5/24/201725948오류 유형: 389. DISM.exe - The specified image in the specified wim is already mounted for read/write access.11205정성태5/24/201725281.NET Framework: 658. C#의 tail call 구현은? [1]11204정성태5/22/201734783개발 환경 구성: 316. 간단하게 살펴보는 Docker for Windows [7]11203정성태5/19/201721978오류 유형: 388. docker - Host does not exist: "default"11202정성태5/19/201722944오류 유형: 387. WPF - There is no registered CultureInfo with the IetfLanguageTag 'ug'.11201정성태5/16/201727691오류 유형: 386. WPF - .NET 3.5 이하에서 TextBox에 한글 입력 시 TextChanged 이벤트의 비정상 종료 문제 [1]111200정성태5/16/201724250오류 유형: 385. WPF - 폰트가 없어 System.IO.FileNotFoundException 예외가 발생하는 경우11199정성태5/16/201724250.NET Framework: 657. CultureInfo.GetCultures가 반환하는 값11198정성태5/10/201727477.NET Framework: 656. Windows Forms의 오류(Exception) 처리 방법에 대한 차이점 설명11197정성태5/8/201722606개발 환경 구성: 315. VHD 파일의 최소 크기111196정성태5/4/201724316오류 유형: 384. Msvm_ImageManagementService WMI 객체를 사용할 때 오류 상황 정리 [1]11195정성태5/3/201725652.NET Framework: 655. .NET Framework 4.7 릴리스11194정성태5/3/201726315오류 유형: 383. net use 명령어로 네트워크 드라이브 연결 시 "System error 67 has occurred." 오류 발생11193정성태5/3/201724022Windows: 141. 설치된 Windows로부터 설치 이미지를 만드는 방법11192정성태5/2/201726304Windows: 140. unattended.xml/autounattend.xml 파일을 마련하는 방법11191정성태5/2/201727183Windows: 139. Dell Venue 8 Pro 태블릿에 USB를 이용한 윈도우 운영체제 설치 방법 ... 106 107 108 109 110 111 [112] 113 114 115 116 117 118 119 120 ...