부모글 보이기/감추기 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를 호출하는 것이 아닐까... 예상해 봅니다. ^^ 정성태 ... 91 92 93 [94] 95 96 97 98 99 100 101 102 103 104 105 ... NoWriterDateCnt.TitleFile(s) 11620정성태7/22/201823789Graphics: 11. Unity로 실습하는 Shader (7) - Blur (평균값, 가우스, 중간값) 필터 [1]111619정성태7/21/201823323Graphics: 10. Unity로 실습하는 Shader (6) - Mosaic Shading11618정성태7/20/201819931개발 환경 구성: 387. 삼성 오디세이(Odyssey) 노트북의 운영체제를 새로 설치하는 방법11617정성태7/20/201820581Team Foundation Server: 50. TFS 소스 코드 관리 기능 (5) - "Rollback", "Rollback Entire Changeset"11616정성태7/17/201819701Graphics: 9. Unity Shader - 전역 변수의 초기화11615정성태7/17/201824103.NET Framework: 788. RawInput을 이용한 키보드/마우스 입력 모니터링111614정성태7/17/201826983Graphics: 8. Unity Shader - Texture의 UV 좌표에 대응하는 Pixel 좌표11613정성태7/16/201823587Graphics: 7. Unity로 실습하는 Shader (5) - Flat Shading11612정성태7/16/201821541Windows: 148. Windows - Raw Input의 Top level collection 의미11611정성태7/15/201821960Graphics: 6. Unity로 실습하는 Shader (4) - 퐁 셰이딩(phong shading)11610정성태7/15/201819316Graphics: 5. Unity로 실습하는 Shader (3) - 고로 셰이딩(gouraud shading) + 퐁 모델(Phong model) + Texture11609정성태7/15/201822312Graphics: 4. Unity로 실습하는 Shader (2) - 고로 셰이딩(gouraud shading) + 퐁 모델(Phong model)11608정성태7/15/201825918Graphics: 3. Unity로 실습하는 Shader (1) - 컬러 반전 및 상하/좌우 뒤집기11607정성태7/14/201826271Graphics: 2. Unity로 실습하는 Shader [1]11606정성태7/13/201827118사물인터넷: 19. PC에 연결해 동작하는 자신만의 USB 장치 만들어 보기111605정성태7/13/201823563사물인터넷: 18. New NodeMCU v3 아두이노 호환 보드의 내장 LED 및 입력 핀 사용법 [1]111604정성태7/12/201822493Math: 47. GeoGebra 기하 (24) - 정다각형111603정성태7/12/201817712Math: 46. GeoGebra 기하 (23) - sqrt(n) 제곱근111602정성태7/11/201818278Math: 45. GeoGebra 기하 (22) - 반전기하학의 원에 관한 반사변환111601정성태7/11/201821398Math: 44. GeoGebra 기하 (21) - 반전기하학의 직선 및 원에 관한 반사변환111600정성태7/10/201820017Math: 43. GeoGebra 기하 (20) - 세 점을 지나는 원111599정성태7/10/201818886Math: 42. GeoGebra 기하 (19) - 두 원의 안과 밖으로 접하는 직선111598정성태7/10/201821119Windows: 147. 시스템 복구 디스크를 USB 디스크에 만드는 방법11597정성태7/10/201823377사물인터넷: 17. Thinary Electronic - ATmega328PB 아두이노 호환 보드의 개발 환경 구성11596정성태7/10/201820667기타: 72. 과거의 용어 설명 - OWIN11595정성태7/10/201826161사물인터넷: 16. New NodeMCU v3 아두이노 호환 보드의 기본 개발 환경 구성 ... 91 92 93 [94] 95 96 97 98 99 100 101 102 103 104 105 ...