부모글 보이기/감추기 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) 11937정성태6/11/201925615개발 환경 구성: 442. .NET Core 3.0 preview 5를 이용해 Windows Forms/WPF 응용 프로그램 개발 [1]11936정성태6/10/201918529Math: 58. C# - 최소 자승법의 1차, 2차 수렴 그래프 변화 확인 [2]111935정성태6/9/201920173.NET Framework: 843. C# - PLplot 출력을 파일이 아닌 Window 화면으로 변경11934정성태6/7/201921521VC++: 133. typedef struct와 타입 전방 선언으로 인한 C2371 오류111933정성태6/7/201919743VC++: 132. enum 정의를 C++11의 enum class로 바꿀 때 유의할 사항111932정성태6/7/201918936오류 유형: 544. C++ - fatal error C1017: invalid integer constant expression111931정성태6/6/201919433개발 환경 구성: 441. C# - CairoSharp/GtkSharp 사용을 위한 프로젝트 구성 방법11930정성태6/5/201920020.NET Framework: 842. .NET Reflection을 대체할 System.Reflection.Metadata 소개 [1]11929정성태6/5/201919522.NET Framework: 841. Windows Forms/C# - 클립보드에 RTF 텍스트를 복사 및 확인하는 방법 [1]11928정성태6/5/201918413오류 유형: 543. PowerShell 확장 설치 시 "Catalog file '[...].cat' is not found in the contents of the module" 오류 발생11927정성태6/5/201919633스크립트: 15. PowerShell ISE의 스크립트를 복사 후 PPT/Word에 붙여 넣으면 한글이 깨지는 문제 [1]11926정성태6/4/201920079오류 유형: 542. Visual Studio - pointer to incomplete class type is not allowed11925정성태6/4/201919917VC++: 131. Visual C++ - uuid 확장 속성과 __uuidof 확장 연산자111924정성태5/30/201921596Math: 57. C# - 해석학적 방법을 이용한 최소 자승법 [1]111923정성태5/30/201921275Math: 56. C# - 그래프 그리기로 알아보는 경사 하강법의 최소/최댓값 구하기111922정성태5/29/201918714.NET Framework: 840. ML.NET 데이터 정규화111921정성태5/28/201924575Math: 55. C# - 다항식을 위한 최소 자승법(Least Squares Method)111920정성태5/28/201916146.NET Framework: 839. C# - PLplot 색상 제어11919정성태5/27/201920538Math: 54. C# - 최소 자승법의 1차 함수에 대한 매개변수를 단순 for 문으로 구하는 방법 [1]111918정성태5/25/201921283Math: 53. C# - 행렬식을 이용한 최소 자승법(LSM: Least Square Method)111917정성태5/24/201922255Math: 52. MathNet을 이용한 간단한 통계 정보 처리 - 분산/표준편차111916정성태5/24/201920148Math: 51. MathNET + OxyPlot을 이용한 간단한 통계 정보 처리 - Histogram111915정성태5/24/201923268Linux: 11. 리눅스의 환경 변수 관련 함수 정리 - putenv, setenv, unsetenv11914정성태5/24/201922204Linux: 10. 윈도우의 GetTickCount와 리눅스의 clock_gettime111913정성태5/23/201918900.NET Framework: 838. C# - 숫자형 타입의 bit(2진) 문자열, 16진수 문자열 구하는 방법111912정성태5/23/201918835VS.NET IDE: 137. Visual Studio 2019 버전 16.1부터 리눅스 C/C++ 프로젝트에 추가된 WSL 지원 ... 76 77 78 79 [80] 81 82 83 84 85 86 87 88 89 90 ...