using Net462DllTest.Signal; using Serein.Library; using Serein.Library.Api; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Threading; using System.Windows.Forms; using System.Windows.Threading; using Serein.Library.Utils; namespace Net462DllTest.Trigger { /// /// 视图管理 /// [AutoRegister] public class ViewManagement : TaskFlowTrigger { private readonly UIContextOperation uiContextOperation; public ViewManagement(UIContextOperation uiContextOperation) { this.uiContextOperation = uiContextOperation; } public int Id = new Random().Next(1, 10000); private readonly List
forms = new List(); /// /// 打开窗口 /// /// 要打开的窗口类型 /// 是否置顶 public void OpenView(Form form, bool isTop) { //Application.Current.Dispatcher. forms.Add(form); uiContextOperation.Invoke(() => { form.TopMost = isTop; form.Show(); }); //environment.IOC.Run(uiContext => //{ // uiContext?.Post(state => { // },null); //}); //var uiContext = SynchronizationContext.Current; //Task.Run(() => //{ // uiContext.Post(_ => // { // }, null); //}); } public void CloseView(Type formType) { var remoteForms = forms.Where(f => f.GetType() == formType).ToArray(); Dispatcher.CurrentDispatcher.Invoke(() => { foreach (Form f in remoteForms) { f.Close(); f.Dispose(); this.forms.Remove(f); } }); } } }