부모글 보이기/감추기 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를 호출하는 것이 아닐까... 예상해 봅니다. ^^ 정성태 ... 151 152 153 154 155 156 157 158 159 160 [161] 162 163 164 165 ... NoWriterDateCnt.TitleFile(s) 1024정성태4/22/201129303오류 유형: 118. Windows 2008 서버에서 Event Viewer / PowerShell 실행 시 비정상 종료되는 문제 [1]1023정성태4/20/201130151.NET Framework: 210. Windbg 환경에서 확인해 본 .NET 메서드 JIT 컴파일 전과 후 [1]1022정성태4/19/201125728디버깅 기술: 38. .NET Disassembly 창에서의 F11(Step-into) 키 동작11021정성태4/18/201128024디버깅 기술: 37. .NET 4.0 응용 프로그램의 Main 함수에 BreakPoint 걸기1020정성태4/18/201128631오류 유형: 117. Failed to find runtime DLL (mscorwks.dll), 0x800040051019정성태4/17/201129255디버깅 기술: 36. Visual Studio의 .NET Disassembly 창의 call 호출에 사용되는 주소의 의미는? [1]11018정성태4/16/201132916오류 유형: 116. 윈도우 업데이트 오류 - 0x8020000E1017정성태4/14/201127728개발 환경 구성: 115. MSBuild - x86/x64, .NET 2/4, debug/release 빌드에 대한 배치 처리11016정성태4/13/201143752개발 환경 구성: 114. Windows Thin PC 설치 [2]1015정성태4/9/201129116.NET Framework: 209. AutoReset, ManualReset, Monitor.Wait의 차이11014정성태4/7/2011106574오류 유형: 115. ORA-12516: TNS:listener could not find available handler with matching protocol stack [2]1013정성태4/7/201124404Team Foundation Server: 45. SharePoint 2010 + TFS 2010 환경에서 ProcessGuidance.html 파일 다운로드 문제1012정성태4/6/201133164.NET Framework: 208. WCF - 접속된 클라이언트의 IP 주소 알아내는 방법 [1]1011정성태3/31/201135502오류 유형: 114. 인증서 갱신 오류 - The request contains no certificate template information.1010정성태3/30/201126208개발 환경 구성: 113. 응용 프로그램 디자인 스케치 도구 - SketchFlow [4]1009정성태3/29/201138585개발 환경 구성: 112. Visual Studio 2010 - .NET Framework 소스 코드 디버깅 [4]1008정성태3/27/201130943.NET Framework: 207. C# - Right operand가 음수인 Shift 연산 결과 [2]1007정성태3/16/201131810개발 환경 구성: 111. Excel - XML 파일 연동 [5]11006정성태3/15/201125550.NET Framework: 206. XML/XSD - 외래키처럼 참조 제한 거는 방법11005정성태3/11/201135350개발 환경 구성: 110. 엑셀 매크로 함수 관련 오류 [2]1004정성태3/3/201124611개발 환경 구성: 109. SharePoint Health Analyzer 디스크 부족 경고 제어1003정성태3/3/201125663오류 유형: 113. SQL Server - DB Attach 시 Parameter name: nColIndex 오류 발생1002정성태3/2/201124019Team Foundation Server: 44. TFS 설치 후, Team Portal의 Dashboard를 빠르게 확인하는 방법1001정성태3/2/201128038Team Foundation Server: 43. TFS 2010 + SharePoint 2010 설치1000정성태3/1/201133011오류 유형: 112. Remote FX RDP 연결 시 오류 유형 2가지 [5]999정성태2/28/201146586개발 환경 구성: 108. RemoteFX - Windows 7 가상 머신에서 DirectX 9c 환경을 제공 [5] ... 151 152 153 154 155 156 157 158 159 160 [161] 162 163 164 165 ...