부모글 보이기/감추기 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) 13718정성태8/27/20247455오류 유형: 921. Visual C++ - error C1083: Cannot open include file: 'float.h': No such file or directory [2]13717정성태8/26/20247056VS.NET IDE: 192. Visual Studio 2022 - Windows XP / 2003용 C/C++ 프로젝트 빌드13716정성태8/21/20246768C/C++: 167. Visual C++ - 윈도우 환경에서 _execv 동작 [1]13715정성태8/19/20247399Linux: 78. 리눅스 C/C++ - 특정 버전의 glibc 빌드 (docker-glibc-builder)13714정성태8/19/20246770닷넷: 2295. C# 12 - 기본 생성자(Primary constructors) (책 오타 수정) [3]13713정성태8/16/20247512개발 환경 구성: 721. WSL 2에서의 Hyper-V Socket 연동13712정성태8/14/20247231개발 환경 구성: 720. Synology NAS - docker 원격 제어를 위한 TCP 바인딩 추가13711정성태8/13/20248086Linux: 77. C# / Linux - zombie process (defunct process) [1]113710정성태8/8/20248018닷넷: 2294. C# 13 - (6) iterator 또는 비동기 메서드에서 ref와 unsafe 사용을 부분적으로 허용113709정성태8/7/20247769닷넷: 2293. C# - safe/unsafe 문맥에 대한 C# 13의 (하위 호환을 깨는) 변화113708정성태8/7/20247565개발 환경 구성: 719. ffmpeg / YoutubeExplode - mp4 동영상 파일로부터 Audio 파일 추출13707정성태8/6/20247796닷넷: 2292. C# - 자식 프로세스의 출력이 4,096보다 많은 경우 Process.WaitForExit 호출 시 hang 현상113706정성태8/5/20247923개발 환경 구성: 718. Hyper-V - 리눅스 VM에 새로운 디스크 추가13705정성태8/4/20248175닷넷: 2291. C# 13 - (5) params 인자 타입으로 컬렉션 허용 [2]113704정성태8/2/20248132닷넷: 2290. C# - 간이 dotnet-dump 프로그램 만들기113703정성태8/1/20247464닷넷: 2289. "dotnet-dump ps" 명령어가 닷넷 프로세스를 찾는 방법13702정성태7/31/20247878닷넷: 2288. Collection 식을 지원하는 사용자 정의 타입을 CollectionBuilder 특성으로 성능 보완113701정성태7/30/20248142닷넷: 2287. C# 13 - (4) Indexer를 이용한 개체 초기화 구문에서 System.Index 연산자 허용113700정성태7/29/20247764디버깅 기술: 200. DLL Export/Import의 Hint 의미13699정성태7/27/20248269닷넷: 2286. C# 13 - (3) Monitor를 대체할 Lock 타입113698정성태7/27/20248225닷넷: 2285. C# - async 메서드에서의 System.Threading.Lock 잠금 처리113697정성태7/26/20247934닷넷: 2284. C# - async 메서드에서의 lock/Monitor.Enter/Exit 잠금 처리113696정성태7/26/20247470오류 유형: 920. dotnet publish - error NETSDK1047: Assets file '...\obj\project.assets.json' doesn't have a target for '...'13695정성태7/25/20247461닷넷: 2283. C# - Lock / Wait 상태에서도 STA COM 메서드 호출 처리113694정성태7/25/20247922닷넷: 2282. C# - ASP.NET Core Web App의 Request 용량 상한값 (Kestrel, IIS)13693정성태7/24/20247248개발 환경 구성: 717. Visual Studio - C# 프로젝트에서 레지스트리에 등록하지 않은 COM 개체 참조 및 사용 방법1 1 2 3 4 5 6 7 8 [9] 10 11 12 13 14 15 ...