提升WPF的启动速度
这有一篇很好的文章,
Improving WPF applications startup time
http://blogs.msdn.com/b/jgoldb/archive/2007/10/10/improving-wpf-applications-startup-time.aspx
摘要几点:
1.Warm start is different with cold start.
2.Analysis start code.
3. Load fewer module, remove unuseful code and reference.
4.avoid unnecessary init
5.consider avoiding Application Configuration.
6. remove Authenticode
generatePublisherEvidence enabled="false"/
7.use neturalResourceLanguageAttribute
8.DataBinding, don't use "DataContext" in xaml.
Get Start time by Coded-UI Test code:
void log(string str) { Trace.WriteLine(string.Format(@"{0} | {1}", DateTime.Now.ToString("hh:mm:ss fff"), str)); } void Test() { foreach (Process p in Process.GetProcesses()) { if (p.ProcessName.ToUpper().Equals("BACKITUP")) { p.Kill(); } } DateTime dt1 = DateTime.Now; log("prepare"); string path = @"TestDemo.exe"; Process.Start(path); log("start"); DateTime dt2 = DateTime.Now; while (true) { try { AutomationElement desktop = AutomationElement.RootElement; var condition = new System.Windows.Automation.PropertyCondition(AutomationElement.NameProperty, "MainWindow"); var des = desktop.FindFirst(TreeScope.Children, condition); if (des == null) continue; else { condition = new System.Windows.Automation.PropertyCondition(AutomationElement.AutomationIdProperty, "button1"); des = des.FindFirst(TreeScope.Children, condition); if (des != null) break; } } catch (Exception ex) { Debug.WriteLine(ex); break; } Thread.Sleep(5); } DateTime dt3 = DateTime.Now; log("End"); var ts = dt3 - dt1; log("total time: " + (ts.TotalMilliseconds / 1000d).ToString() + "s"); }