VS 代码片段集
片段1:用于线程执行代码,耗时操作时加载Loging;
<?xml version="1.0" encoding="utf-8"?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>BW</Title> <Shortcut>BW</Shortcut> <Description>线程运行加载loging的代码片段_毛阳</Description> <Author>Microsoft Corporation</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>Time</ID> <Default>0104.</Default> <ToolTip>显示的内容</ToolTip> </Literal> </Declarations> <Code Language="csharp"><![CDATA[ BackgroundWorker bgMeet = new BackgroundWorker(); bgMeet.WorkerReportsProgress = true; bgMeet.DoWork += new DoWorkEventHandler((s, ed) => { TreeViewItem ti = null; this.Dispatcher.Invoke(new Action(() => { //这里写等待时候发生的loging... //这里写执行的代码 })); }); bgMeet.RunWorkerCompleted += new RunWorkerCompletedEventHandler((s, se) => { this.Dispatcher.Invoke(new Action(() => { //这里写结束时候loging...的状态 })); }); bgMeet.RunWorkerAsync();]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
2.弹出消息框:
switch (System.Windows.MessageBox.Show("确认保存?", "询问", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Exclamation)) { case System.Windows.MessageBoxResult.Yes: // ... break; case System.Windows.MessageBoxResult.No: return; case System.Windows.MessageBoxResult.Cancel: return; }