부모글 보이기/감추기 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를 호출하는 것이 아닐까... 예상해 봅니다. ^^ 정성태 1 2 3 4 5 6 7 8 9 10 11 [12] 13 14 15 ... NoWriterDateCnt.TitleFile(s) 13641정성태6/11/20248686Linux: 71. Ubuntu 20.04를 22.04로 업데이트13640정성태6/10/20248847Phone: 21. C# MAUI - Android 환경에서의 파일 다운로드(DownloadManager)13639정성태6/8/20248463오류 유형: 906. C# MAUI - Android Emulator에서 "Waiting For Debugger"로 무한 대기13638정성태6/8/20248539오류 유형: 905. C# MAUI - 추가한 layout XML 파일이 Resource.Layout 멤버로 나오지 않는 문제13637정성태6/6/20248460Phone: 20. C# MAUI - 유튜브 동영상을 MediaElement로 재생하는 방법13636정성태5/30/20248098닷넷: 2264. C# - 형식 인자로 인터페이스를 갖는 제네릭 타입으로의 형변환113635정성태5/29/20248971Phone: 19. C# MAUI - 안드로이드 "Share" 대상으로 등록하는 방법13634정성태5/24/20249447Phone: 18. C# MAUI - 안드로이드 플랫폼에서의 Activity 제어 [1]13633정성태5/22/20248973스크립트: 64. 파이썬 - ASGI를 만족하는 최소한의 구현 코드13632정성태5/20/20248588Phone: 17. C# MAUI - Android 내에 Web 서비스 호스팅13631정성태5/19/20249344Phone: 16. C# MAUI - /Download 등의 공용 디렉터리에 접근하는 방법 [1]13630정성태5/19/20248892닷넷: 2263. C# - Thread가 Task보다 더 빠르다는 어떤 예제(?)13629정성태5/18/20249178개발 환경 구성: 710. Android - adb.exe를 이용한 파일 전송13628정성태5/17/20248553개발 환경 구성: 709. Windows - WHPX(Windows Hypervisor Platform)를 이용한 Android Emulator 가속13627정성태5/17/20248633오류 유형: 904. 파이썬 - UnicodeEncodeError: 'ascii' codec can't encode character '...' in position ...: ordinal not in range(128)13626정성태5/15/20248906Phone: 15. C# MAUI - MediaElement Source 경로 지정 방법113625정성태5/14/20248944닷넷: 2262. C# - Exception Filter 조건(when)을 갖는 catch 절의 IL 구조13624정성태5/12/20248733Phone: 14. C# - MAUI에서 MediaElement 사용113623정성태5/11/20248431닷넷: 2261. C# - 구글 OAuth의 JWT (JSON Web Tokens) 해석113622정성태5/10/20249234닷넷: 2260. C# - Google 로그인 연동 (ASP.NET 예제)113621정성태5/10/20248644오류 유형: 903. IISExpress - Failed to register URL "..." for site "..." application "/". Error description: Cannot create a file when that file already exists. (0x800700b7)13620정성태5/9/20248573VS.NET IDE: 190. Visual Studio가 node.exe를 경유해 Edge.exe를 띄우는 경우13619정성태5/7/20248874닷넷: 2259. C# - decimal 저장소의 비트 구조113618정성태5/6/20248666닷넷: 2258. C# - double (배정도 실수) 저장소의 비트 구조113617정성태5/5/20249495닷넷: 2257. C# - float (단정도 실수) 저장소의 비트 구조113616정성태5/3/20248658닷넷: 2256. ASP.NET Core 웹 사이트의 HTTP/HTTPS + Dual mode Socket (IPv4/IPv6) 지원 방법1 1 2 3 4 5 6 7 8 9 10 11 [12] 13 14 15 ...