andrew4582

ah_WriteOutput.snippet

Mar 5th, 2011
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.53 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.     <CodeSnippet Format="1.0.0">
  4.         <Header>
  5.             <Title>AH WriteOutput</Title>
  6.             <Shortcut>ahWriteOutput</Shortcut>
  7.             <Description>Code snippet created on: 2/23/2011 5:29:10 PM</Description>
  8.             <Author>Andrew Hodgson</Author>
  9.             <SnippetTypes>
  10.                 <SnippetType>Expansion</SnippetType>
  11.             </SnippetTypes>
  12.         </Header>
  13.         <Snippet>
  14.             <Declarations>
  15.                 <Literal>
  16.                     <ID>type</ID>
  17.                     <ToolTip>Property type</ToolTip>
  18.                     <Default>string</Default>
  19.                 </Literal>
  20.                 <Literal>
  21.                     <ID>property</ID>
  22.                     <ToolTip>Property name</ToolTip>
  23.                     <Default>MyProperty</Default>
  24.                 </Literal>
  25.             </Declarations>
  26.             <Code Language="csharp">
  27.                 <![CDATA[        void WriteOutput(string format,params object[] args) {
  28.            WriteOutput(string.Format(format,args));
  29.        }
  30.        /// <summary>
  31.        /// Writes output to a windows form using InvokeRequired property
  32.        /// </summary>
  33.        /// <param name="value">Data to output</param>
  34.        void WriteOutput(object value) {
  35.            string text = value == null ? string.Empty : value.ToString();
  36.            text += Environment.NewLine;
  37.  
  38.            Action<string> writeAction = (s) => richTextBox1.AppendText(s);
  39.            if(InvokeRequired)
  40.                BeginInvoke(new Action<string>(writeAction),text);
  41.            else
  42.                writeAction(text);
  43.        }$end$]]>
  44.             </Code>
  45.         </Snippet>
  46.     </CodeSnippet>
  47. </CodeSnippets>
Advertisement
Add Comment
Please, Sign In to add comment