public Main() { InitializeComponent(); MainVM = new MainVM{Main = this}; rootGrid.DataContext = MainVM; InitMenus(); Application.Current.Properties.Add("MainVM", MainVM); //修复最大化盖住任务栏问题 MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight; }
static void Run(CancellationToken ct, MainVM vm) { while (!ct.IsCancellationRequested) { Func<int> regCount = () => MainVM.GetUnreadLogCount(vm.CurrentUser.Id); AsyncCallback acbRegCount = i => vm.Dispatcher.Invoke( new Action(() => { int dResult = regCount.EndInvoke(i); vm.UnreadLogCount = dResult; } )); regCount.BeginInvoke(acbRegCount, null); Thread.Sleep(120000); } }
public void Begin(MainVM vm) { _cts = new CancellationTokenSource(); var t = new Task(() => Run(_cts.Token, vm), _cts.Token); t.Start(); }