부모글 보이기/감추기 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를 호출하는 것이 아닐까... 예상해 봅니다. ^^ 정성태 ... 151 152 153 154 155 156 157 158 159 160 161 162 163 164 [165] ... NoWriterDateCnt.TitleFile(s) 957정성태12/6/201033030디버깅 기술: 31. Windbg - Visual Studio 디버그 상태에서 종료해 버리는 응용 프로그램 [3]953정성태11/28/201038228.NET Framework: 193. 페이스북(Facebook) 계정으로 로그인하는 C# 웹 사이트 제작 [5]952정성태11/25/201026865.NET Framework: 192. GC의 부하는 상대적인 것! [4]950정성태11/18/201078561.NET Framework: 191. ClickOnce - 관리자 권한 상승하는 방법 [17]2954정성태11/29/201050129 .NET Framework: 191.1. [답변] 클릭원스 - 요청한 작업을 수행하려면 권한 상승이 필요합니다. (Exception from HRESULT: 0x800702E4) [2]949정성태11/16/201028595오류 유형: 109. System.ServiceModel.Security.SecurityNegotiationException948정성태11/16/201037741.NET Framework: 190. 트위터 계정으로 로그인하는 C# 웹 사이트 제작 [7]1947정성태11/14/201042586.NET Framework: 189. Mono Cecil로 만들어 보는 .NET Decompiler [1]1946정성태11/11/201042913.NET Framework: 188. .NET 64비트 응용 프로그램에서 왜 (2GB) OutOfMemoryException 예외가 발생할까? [1]1945정성태11/11/201026496VC++: 44. C++/CLI 컴파일 오류 - error C4368: mixed types are not supported944정성태11/11/201033206VC++: 43. C++/CLI 컴파일 오류 - error C2872: 'IServiceProvider' : ambiguous symbol could be ...943정성태11/8/201032148디버깅 기술: 30. windbg ".loadby sos" 명령어 [2]942정성태11/7/201044343.NET Framework: 187. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 [7]3941정성태11/6/201026516.NET Framework: 186. windbg로 확인하는 .NET CLR LCG 메서드(DynamicMethod) [1]1940정성태11/6/201027587.NET Framework: 185. windbg로 확인하는 .NET CLR 메서드1939정성태10/24/201034147Windows: 51. RDP로 접속한 Windows Server 2008 R2 환경에서 Aero Glass 활성화 [1]938정성태10/23/201026151디버깅 기술: 29. Windbg - Hyper-V 윈도우 7 원격 디버깅 구성 [1]937정성태10/22/201032117DDK: 5. NT Legacy 드라이버: 프로세스(EXE) 생성/제거 모니터링 [3]1936정성태10/21/201031247DDK: 4. Device Driver 응용 프로그램의 빌드 스크립트 - 두 번째 이야기 [2]1935정성태10/17/201031885디버깅 기술: 28. Windbg - 윈도우 핸들 테이블 [3]934정성태10/11/201035005디버깅 기술: 27. Windbg - Local Kernel Debug 모드 [2]933정성태10/10/201027076.NET Framework: 184. 닷넷에서 호출 스택의 메서드에 대한 인자 값 확인이 가능할까? [2]1932정성태10/10/201030306DDK: 3. NT Legacy 드라이버를 이용하여 C#에서 Port 입출력1931정성태9/30/201024926오류 유형: 108. Net.Tcp Listener Adapter 서비스 시작 실패930정성태9/30/201024105웹: 16. 윈도우 미디어 플레이어 - 일시 정지/시작을 스크립트에서 감지929정성태9/17/201025486웹: 15. IE 9 - 작업 표시줄의 웹 사이트 바로가기 사용자 정의 - JumpLists [3]1 ... 151 152 153 154 155 156 157 158 159 160 161 162 163 164 [165] ...