부모글 보이기/감추기 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) 11796정성태12/19/201819084개발 환경 구성: 424. vcpkg - "File does not have expected hash" 오류를 무시하는 방법11795정성태12/19/201822483Windows: 154. PowerShell - Zone 별로 DNS 레코드 유형 정보 조회 [1]11794정성태12/16/201818376오류 유형: 508. Get-AzureWebsite : Request to a downlevel service failed.11793정성태12/16/201821224개발 환경 구성: 423. NuGet 패키지 제작 - Native와 Managed DLL을 분리하는 방법 [1]11792정성태12/11/201820063Graphics: 34. .NET으로 구현하는 OpenGL (11) - Per-Pixel Lighting111791정성태12/11/201820270VS.NET IDE: 130. C/C++ 프로젝트의 시작 프로그램으로 .NET Core EXE를 지정하는 경우 닷넷 디버깅이 안 되는 문제 [1]11790정성태12/11/201819244오류 유형: 507. Could not save daemon configuration to C:\ProgramData\Docker\config\daemon.json: Access to the path 'C:\ProgramData\Docker\config' is denied.11789정성태12/10/201833252Windows: 153. C# - USB 장치의 연결 및 해제 알림을 위한 WM_DEVICECHANGE 메시지 처리 [2]211788정성태12/4/201819059오류 유형: 506. SqlClient - Value was either too large or too small for an Int32.Couldn't store <2151292191> in ... Column11787정성태11/29/201823232Graphics: 33. .NET으로 구현하는 OpenGL (9), (10) - OBJ File Format, Loading 3D Models111786정성태11/29/201820189오류 유형: 505. OpenGL.NET 예제 실행 시 "Managed Debugging Assistant 'CallbackOnCollectedDelegate'" 예외 발생11785정성태11/21/201822125디버깅 기술: 120. windbg 분석 사례 - ODP.NET 사용 시 Finalizer에서 System.AccessViolationException 예외 발생으로 인한 비정상 종료11784정성태11/18/201821211Graphics: 32. .NET으로 구현하는 OpenGL (7), (8) - Matrices and Uniform Variables, Model, View & Projection Matrices111783정성태11/18/201820079오류 유형: 504. 윈도우 환경에서 docker가 설치된 컴퓨터 간의 ping IP 주소 풀이 오류11782정성태11/18/201818533Windows: 152. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선순위 조정 기능 - 두 번째 이야기11781정성태11/17/201822507개발 환경 구성: 422. SFML.NET 라이브러리 설정 방법 [1]111780정성태11/17/201823184오류 유형: 503. vcpkg install bzip2 빌드 에러 - "Error: Building package bzip2:x86-windows failed with: BUILD_FAILED"11779정성태11/17/201824007개발 환경 구성: 421. vcpkg 업데이트 [1]11778정성태11/14/201821034.NET Framework: 803. UWP 앱에서 한 컴퓨터(localhost, 127.0.0.1) 내에서의 소켓 연결11777정성태11/13/201822005오류 유형: 502. Your project does not reference "..." framework. Add a reference to "..." in the "TargetFrameworks" property of your project file and then re-run NuGet restore.11776정성태11/13/201820225.NET Framework: 802. Windows에 로그인한 계정이 마이크로소프트의 계정인지, 로컬 계정인지 알아내는 방법11775정성태11/13/201821313Graphics: 31. .NET으로 구현하는 OpenGL (6) - Texturing111774정성태11/8/201820355Graphics: 30. .NET으로 구현하는 OpenGL (4), (5) - Shader111773정성태11/7/201820081Graphics: 29. .NET으로 구현하는 OpenGL (3) - Index Buffer111772정성태11/6/201821594Graphics: 28. .NET으로 구현하는 OpenGL (2) - VAO, VBO111771정성태11/5/201820655사물인터넷: 56. Audio Jack 커넥터의 IR 적외선 송신기 - 두 번째 이야기 [1] ... 76 77 78 79 80 81 82 83 84 85 86 [87] 88 89 90 ...