부모글 보이기/감추기 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를 호출하는 것이 아닐까... 예상해 봅니다. ^^ 정성태 ... 91 92 93 94 95 96 97 98 99 100 [101] 102 103 104 105 ... NoWriterDateCnt.TitleFile(s) 11441정성태1/18/201817370오류 유형: 447. ASP.NET Core 배포 오류 - Ensure that restore has run and that you have included '...' in the TargetFrameworks for your project.11440정성태1/17/201820686.NET Framework: 727. ASP.NET의 HttpContext.Current 구현에 대응하는 ASP.NET Core의 IHttpContextAccessor/HttpContextAccessor 사용법111439정성태1/17/201826369기타: 69. C# - CPU 100% 부하 주는 프로그램111438정성태1/17/201820266오류 유형: 446. Error CS0234 The type or namespace name 'ITuple' does not exist in the namespace11437정성태1/17/201819852VS.NET IDE: 124. Platform Toolset 설정에 따른 Visual C++의 헤더 파일 기본 디렉터리11436정성태1/16/201822261개발 환경 구성: 352. ASP.NET Core (EXE) 프로세스가 IIS에서 호스팅되는 방법 - ASP.NET Core Module(AspNetCoreModule) [4]11435정성태1/16/201823312개발 환경 구성: 351. OWIN 웹 서버(EXE)를 IIS에서 호스팅하는 방법 - HttpPlatformHandler (Reverse Proxy)211434정성태1/15/201823974개발 환경 구성: 350. 사용자 정의 웹 서버(EXE)를 IIS에서 호스팅하는 방법 - HttpPlatformHandler (Reverse Proxy)211433정성태1/15/201822163개발 환경 구성: 349. dotnet ef 명령어 사용을 위한 준비11432정성태1/11/201828562.NET Framework: 726. WPF + Direct2D + SharpDX 출력 C# 예제211431정성태1/11/201825704.NET Framework: 725. C# - 동기 방식이면서 비동기 메서드(awaitable)처럼 구현한 사례 [9]11430정성태1/10/201829183.NET Framework: 724. WPF + Direct2D 출력 C# 예제 [2]111429정성태1/9/201819750개발 환경 구성: 348. ASP.NET Core 2.1 Preview 버전 적용 방법11428정성태1/6/201822937개발 환경 구성: 347. WinForm 프로젝트를 WPF 프로젝트 유형으로 변경하는 방법111427정성태1/5/201820286오류 유형: 445. vcpkg 빌드 오류 - Starting the CLR failed with HRESULT 8004015311426정성태1/5/201830470오류 유형: 444. curl로 호출할 때 발생하는 오류 정리11425정성태1/4/201821145개발 환경 구성: 346. ASP.NET Core Web Application을 IIS에서 호스팅하는 방법 (2)11424정성태1/4/201820595개발 환경 구성: 345. ASP.NET Core 프로젝트를 명령행에서 빌드하는 방법11423정성태1/3/201838990VC++: 123. 내가 만든 코드보다 OpenCV의 속도가 월등히 빠른 이유 [8]211422정성태1/2/201829122.NET Framework: 723. C# - OpenCvSharp 사용 시 C/C++을 이용한 속도 향상 (for 루프 연산) [4]111421정성태1/2/201821330오류 유형: 443. Visual Studio - nuget configuration is invalid11420정성태12/30/201725419.NET Framework: 722. C# - Windows 10 운영체제의 데스크톱 앱에서 음성인식(SpeechRecognizer) 사용하는 방법 [3]111419정성태12/23/201727602.NET Framework: 721. WebClient 타입의 ...Async 메서드 호출은 왜 await + 동기 호출 시 hang 현상이 발생할까요? [2]111418정성태12/23/201737392.NET Framework: 720. 비동기 메서드 내에서 await 시 ConfigureAwait 호출 의미 [2]111417정성태12/22/201723248.NET Framework: 719. Task를 포함하는 async 메서드의 동작 방식 [2]11416정성태12/21/201720357.NET Framework: 718. AsyncTaskMethodBuilder.Create() 메서드 동작 방식 [2] ... 91 92 93 94 95 96 97 98 99 100 [101] 102 103 104 105 ...