부모글 보이기/감추기 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) 11922정성태5/29/201920103.NET Framework: 840. ML.NET 데이터 정규화111921정성태5/28/201926233Math: 55. C# - 다항식을 위한 최소 자승법(Least Squares Method)111920정성태5/28/201916882.NET Framework: 839. C# - PLplot 색상 제어11919정성태5/27/201922175Math: 54. C# - 최소 자승법의 1차 함수에 대한 매개변수를 단순 for 문으로 구하는 방법 [1]111918정성태5/25/201922060Math: 53. C# - 행렬식을 이용한 최소 자승법(LSM: Least Square Method)111917정성태5/24/201923494Math: 52. MathNet을 이용한 간단한 통계 정보 처리 - 분산/표준편차111916정성태5/24/201921482Math: 51. MathNET + OxyPlot을 이용한 간단한 통계 정보 처리 - Histogram111915정성태5/24/201924979Linux: 11. 리눅스의 환경 변수 관련 함수 정리 - putenv, setenv, unsetenv11914정성태5/24/201923676Linux: 10. 윈도우의 GetTickCount와 리눅스의 clock_gettime111913정성태5/23/201919557.NET Framework: 838. C# - 숫자형 타입의 bit(2진) 문자열, 16진수 문자열 구하는 방법111912정성태5/23/201920175VS.NET IDE: 137. Visual Studio 2019 버전 16.1부터 리눅스 C/C++ 프로젝트에 추가된 WSL 지원11911정성태5/23/201919350VS.NET IDE: 136. Visual Studio 2019 - 리눅스 C/C++ 프로젝트에 인텔리센스가 동작하지 않는 경우11910정성태5/23/201928124Math: 50. C# - MathNet.Numerics의 Matrix(행렬) 연산 [1]111909정성태5/22/201922892.NET Framework: 837. C# - PLplot 사용 예제 [1]111908정성태5/22/201921731.NET Framework: 836. C# - Python range 함수 구현111907정성태5/22/201918223오류 유형: 541. msbuild - MSB4024 The imported project file "...targets" could not be loaded11906정성태5/21/201918570.NET Framework: 835. .NET Core/C# - 리눅스 syslog에 로그 남기는 방법11905정성태5/21/201918886.NET Framework: 834. C# - 폴더 경로 문자열에서 "..", "." 표기를 고려한 최종 문자열을 얻는 방법 - 두 번째 이야기11904정성태5/21/201927823.NET Framework: 833. C# - Open Hardware Monitor를 이용한 CPU 온도 정보 [1]111903정성태5/21/201921563오류 유형: 540. .NET Core - System.PlatformNotSupportedException: The named version of this synchronization primitive is not supported on this platform.11902정성태5/21/201919087오류 유형: 539. mstest 실행 시 "The directory name is invalid." 오류 발생11901정성태5/21/201921599오류 유형: 538. msbuild 오류 - Could not find a part of the path '%LOCALAPPDATA%\Temp\2\.NETFramework,Version=v4.0.AssemblyAttributes.cs'11900정성태5/18/201920441오류 유형: 537. "sfc /scannow" 실행 중 시스템이 부팅되는 현상11899정성태5/17/201921175Linux: 9. Linux에서 윈도우의 OutputDebugString 대신 사용할 수 있는 syslog [1]11898정성태5/16/201922747VC++: 130. C++ string의 c_str과 data 함수의 차이점 [3]11897정성태5/16/201929310오류 유형: 536. Visual Studio - "Developer Pack"을 설치했는데도 "대상 프레임워크" 목록에 나오지 않는 경우 [2] ... 76 77 78 79 80 81 [82] 83 84 85 86 87 88 89 90 ...