确保在STA线程中运行

张开发
2026/4/18 6:23:22 15 分钟阅读

分享文章

确保在STA线程中运行
// 确保在STA线程中运行if (Thread.CurrentThread.GetApartmentState() ! ApartmentState.STA){var thread new Thread(() {var guideForm new StartupGuidePage();guideForm.FormClosed (sender, e) {// 导航窗体关闭后可执行主窗体后续逻辑如果需要// 这里可根据实际情况比如主窗体是否需要等待导航窗体关闭再继续等};Application.Run(guideForm);});thread.SetApartmentState(ApartmentState.STA);thread.IsBackground true;thread.Start();}else{var guideForm new StartupGuidePage();guideForm.Show(this); // 非模态显示避免阻塞根据需要调整}

更多文章