부모글 보이기/감추기 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) 13629정성태5/18/202410191개발 환경 구성: 710. Android - adb.exe를 이용한 파일 전송13628정성태5/17/20249428개발 환경 구성: 709. Windows - WHPX(Windows Hypervisor Platform)를 이용한 Android Emulator 가속13627정성태5/17/20249543오류 유형: 904. 파이썬 - UnicodeEncodeError: 'ascii' codec can't encode character '...' in position ...: ordinal not in range(128)13626정성태5/15/202410595Phone: 15. C# MAUI - MediaElement Source 경로 지정 방법113625정성태5/14/202410028닷넷: 2262. C# - Exception Filter 조건(when)을 갖는 catch 절의 IL 구조13624정성태5/12/20249741Phone: 14. C# - MAUI에서 MediaElement 사용113623정성태5/11/20249263닷넷: 2261. C# - 구글 OAuth의 JWT (JSON Web Tokens) 해석113622정성태5/10/202411003닷넷: 2260. C# - Google 로그인 연동 (ASP.NET 예제)113621정성태5/10/202410183오류 유형: 903. IISExpress - Failed to register URL "..." for site "..." application "/". Error description: Cannot create a file when that file already exists. (0x800700b7)13620정성태5/9/20249569VS.NET IDE: 190. Visual Studio가 node.exe를 경유해 Edge.exe를 띄우는 경우13619정성태5/7/202410267닷넷: 2259. C# - decimal 저장소의 비트 구조 [1]113618정성태5/6/20249436닷넷: 2258. C# - double (배정도 실수) 저장소의 비트 구조113617정성태5/5/202411142닷넷: 2257. C# - float (단정도 실수) 저장소의 비트 구조113616정성태5/3/20249419닷넷: 2256. ASP.NET Core 웹 사이트의 HTTP/HTTPS + Dual mode Socket (IPv4/IPv6) 지원 방법113615정성태5/3/202411163닷넷: 2255. C# 배열을 Numpy ndarray 배열과 상호 변환13614정성태5/2/202410952닷넷: 2254. C# - COM 인터페이스의 상속 시 중복으로 메서드를 선언13613정성태5/1/20249710닷넷: 2253. C# - Video Capture 장치(Camera) 열거 및 지원 포맷 조회113612정성태4/30/202410745오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file13611정성태4/29/20249646닷넷: 2252. C# - GUID 타입 전용의 UnmanagedType.LPStruct - 두 번째 이야기113610정성태4/28/202410526닷넷: 2251. C# - 제네릭 인자를 가진 타입을 생성하는 방법 - 두 번째 이야기13609정성태4/27/202410590닷넷: 2250. PInvoke 호출 시 참조 타입(class)을 마샬링하는 [IN], [OUT] 특성113608정성태4/26/202410948닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?113607정성태4/25/202410994닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동13606정성태4/24/202410924닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)113605정성태4/23/202412421닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동113604정성태4/22/20249543오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames. 1 2 3 4 5 6 7 8 9 10 11 12 13 [14] 15 ...