부모글 보이기/감추기 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를 호출하는 것이 아닐까... 예상해 봅니다. ^^ 정성태 ... 76 77 78 79 80 81 [82] 83 84 85 86 87 88 89 90 ... NoWriterDateCnt.TitleFile(s) 11887정성태5/8/201921525.NET Framework: 829. C# - yield 문을 사용할 수 있는 메서드의 조건11886정성태5/7/201919337오류 유형: 534. mstest.exe 실행 시 "Visual Studio Enterprise is required to execute the test." 오류 [2]11885정성태5/7/201916283오류 유형: 533. mstest.exe 실행 시 "File extension specified '.loadtest' is not a valid test extension." 오류 발생11884정성태5/5/201921080.NET Framework: 828. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기11883정성태5/3/201926249.NET Framework: 827. C# - 인터넷 시간 서버로부터 받은 시간을 윈도우에 적용하는 방법111882정성태5/2/201922547.NET Framework: 826. (번역글) .NET Internals Cookbook Part 11 - Various C# riddles111881정성태4/28/201922651오류 유형: 532. .NET Core 프로젝트로 마이그레이션 시 "CS0579 Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute" 오류 발생11880정성태4/25/201918509오류 유형: 531. 이벤트 로그 오류 - Task Scheduling Error: m->NextScheduledSPRetry 1547, m->NextScheduledEvent 154711879정성태4/24/201926944.NET Framework: 825. (번역글) .NET Internals Cookbook Part 10 - Threads, Tasks, asynchronous code and others211878정성태4/22/201922727.NET Framework: 824. (번역글) .NET Internals Cookbook Part 9 - Finalizers, queues, card tables and other GC stuff111877정성태4/22/201922778.NET Framework: 823. (번역글) .NET Internals Cookbook Part 8 - C# gotchas111876정성태4/21/201921748.NET Framework: 822. (번역글) .NET Internals Cookbook Part 7 - Word tearing, locking and others111875정성태4/21/201922818오류 유형: 530. Visual Studo에서 .NET Core 프로젝트를 열 때 "One or more errors occurred." 오류 발생11874정성태4/20/201923000.NET Framework: 821. (번역글) .NET Internals Cookbook Part 6 - Object internals111873정성태4/19/201921620.NET Framework: 820. (번역글) .NET Internals Cookbook Part 5 - Methods, parameters, modifiers111872정성태4/17/201922388.NET Framework: 819. (번역글) .NET Internals Cookbook Part 4 - Type members111871정성태4/16/201920938.NET Framework: 818. (번역글) .NET Internals Cookbook Part 3 - Initialization tricks [3]111870정성태4/16/201919285.NET Framework: 817. Process.Start로 실행한 콘솔 프로그램의 출력 결과를 얻는 방법111869정성태4/15/201925134.NET Framework: 816. (번역글) .NET Internals Cookbook Part 2 - GC-related things [2]211868정성태4/15/201921109.NET Framework: 815. CER(Constrained Execution Region)이란?111867정성태4/15/201920291.NET Framework: 814. Critical Finalizer와 SafeHandle의 사용 의미111866정성태4/9/201923359Windows: 159. 네트워크 공유 폴더(net use)에 대한 인증 정보는 언제까지 유효할까요?11865정성태4/9/201919232오류 유형: 529. 제어판 - C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools is not accessible.11864정성태4/9/201917892오류 유형: 528. '...' could be '0': this does not adhere to the specification for the function '...'11863정성태4/9/201917791디버깅 기술: 127. windbg - .NET x64 EXE의 EntryPoint11862정성태4/7/201920292개발 환경 구성: 437. .NET EXE의 ASLR 기능을 끄는 방법 ... 76 77 78 79 80 81 [82] 83 84 85 86 87 88 89 90 ...