<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for The ways of Mauri</title>
	<atom:link href="http://blog.themobilebrand.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.themobilebrand.com</link>
	<description></description>
	<lastBuildDate>Wed, 22 Feb 2012 15:24:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by Angela</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-256</link>
		<dc:creator>Angela</dc:creator>
		<pubDate>Wed, 22 Feb 2012 15:24:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-256</guid>
		<description>I hope this makes sense, I used this skelton to create a windows service that queries  2 database work tables, one that holds raw blob data that needs to be decompressed and converted from RTF to Plain Text/HTML and one that is it&#039;s parent table.  I query the parent work table and put the results into a datatable, and close the conn. The service loops through the datatable, and queries a child work table that holds the raw blobs.  The results are then inserted/updated into their permanent decompressed/converted tables.  Once this is done, I go back to the raw work tables and delete the rows.  Then I put the service to sleep for 10 secs to allow the work tables to fill back up.  I open/close a connection for each database call.  The problem I&#039;m having is excessive blocking in the SQL Server 2005 database when I delete the processed rows from the work tables. I used Activity Monitor to view the processes that are being generated and I see several connections being made to delete the rows?  This confuses me because I close the connection after each database call.</description>
		<content:encoded><![CDATA[<p>I hope this makes sense, I used this skelton to create a windows service that queries  2 database work tables, one that holds raw blob data that needs to be decompressed and converted from RTF to Plain Text/HTML and one that is it&#8217;s parent table.  I query the parent work table and put the results into a datatable, and close the conn. The service loops through the datatable, and queries a child work table that holds the raw blobs.  The results are then inserted/updated into their permanent decompressed/converted tables.  Once this is done, I go back to the raw work tables and delete the rows.  Then I put the service to sleep for 10 secs to allow the work tables to fill back up.  I open/close a connection for each database call.  The problem I&#8217;m having is excessive blocking in the SQL Server 2005 database when I delete the processed rows from the work tables. I used Activity Monitor to view the processes that are being generated and I see several connections being made to delete the rows?  This confuses me because I close the connection after each database call.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by Anil kumar</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-255</link>
		<dc:creator>Anil kumar</dc:creator>
		<pubDate>Tue, 31 Jan 2012 03:54:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-255</guid>
		<description>Great tuts keep going</description>
		<content:encoded><![CDATA[<p>Great tuts keep going</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by mvanbeusekom</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-254</link>
		<dc:creator>mvanbeusekom</dc:creator>
		<pubDate>Wed, 25 Jan 2012 14:04:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-254</guid>
		<description>Hi CSDull,

I am glad you found the tutorial helpful.

In remark to your questions there are several solutions of course. Below I will try to give a possible example solution (the full source can be found &lt;a href=&quot;http://blog.themobilebrand.com/wp-content/uploads/2012/01/EventLogger-Scheduled.zip&quot; title=&quot;Scheduled version of the EventLogger&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;, Note: I have upgraded the solution to Visual Studio 2008)

First add a new constructor to the &#039;EventLoggerApp&#039; which will initialize the &#039;EventLog&#039; class and remove the code from the &#039;Start()&#039; method, like this:
&lt;pre lang=&quot;csharp&quot;&gt;
public EventLoggerApp()
{
  // Check if the EventLoggerService Event Log Source exists, when not
  // create it
  if (!EventLog.SourceExists(&quot;EventLoggerSource&quot;))
    EventLog.CreateEventSource(&quot;EventLoggerSource&quot;, &quot;Event Logger&quot;);

  _log = new EventLog();
  _log.Source = &quot;EventLoggerSource&quot;;
}&lt;/pre&gt;

New &#039;Start()&#039; method will look like this:
&lt;pre lang=&quot;csharp&quot;&gt;
public void Start()
{
  _thread = new Thread(new ThreadStart(Execute));
  _thread.Start();
}&lt;/pre&gt;

The next step is to modify the &#039;Execute()&#039; method to run according to a schedule, an example solution could look like this:
&lt;pre lang=&quot;csharp&quot;&gt;
private void Execute()
{
  // Loop until the thread gets aborted
  try
  {
    DateTime startTime = default(DateTime);
	double intervalInMinutes = 0;

	if (!DateTime.TryParse(ConfigurationManager.AppSettings[&quot;StartTime&quot;], out startTime))
	{
	  _log.WriteEntry(&quot;ERROR (EventLoggerApp.Execute): Unable to parse start date as datetime, check configuration.&quot;);
	  return;
	}

	if (!double.TryParse(ConfigurationManager.AppSettings[&quot;IntervalInMinutes&quot;], out intervalInMinutes))
	{
	  _log.WriteEntry(&quot;ERROR (EventLoggerApp.Execute): Unable to parse interval as integer, check configuration.&quot;);
	  return;
	}

	DateTime nextRunDate = startTime;

	while (true)
	{
	  if (nextRunDate.CompareTo(DateTime.Now) &lt;= 0)
	  {
	    // Call the RunOnce method to execute the application logic
		RunOnce();

		// Calculate the next time to run
		nextRunDate = nextRunDate.AddMinutes(intervalInMinutes);
	  }

	  // Sleep for ten seconds
	  Thread.Sleep(10000);
	}
  }
  catch (ThreadAbortException)
  {
    _log.WriteEntry(&quot;INFO (EventLoggerApp.Execute): Thread aborted.&quot;);
  }
}&lt;/pre&gt;

Next add the &#039;RunOnce()&#039; method to the &#039;EventLoggerApp&#039; like this:
&lt;pre lang=&quot;csharp&quot;&gt;
public void RunOnce()
{
  // TODO: Put you application logic here (like create the log entry in the eventlogger example)
  _log.WriteEntry(string.Format(&quot;INFO (EventLoggerApp.Execute): Current time is: {0}.&quot;, DateTime.Now.ToString(&quot;HH:mm:ss&quot;)));
}&lt;/pre&gt;

The last thing to do is to add an Application Configuration File to the project and add the &#039;StartTime&#039; and &#039;IntervalInMinutes&#039; settings like this:
&lt;pre lang=&quot;xml&quot;&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;configuration&gt;
  &lt;appSettings&gt;
    &lt;add key=&quot;StartTime&quot; value=&quot;14:00&quot; /&gt;
    &lt;add key=&quot;IntervalInMinutes&quot; value=&quot;720&quot; /&gt;
  &lt;/appSettings&gt;
&lt;/configuration&gt;
&lt;/pre&gt;

Now to run the application manually you can simply run it from the Command Line. And by changing the &#039;Program&#039; class a little we can simple type &#039;run&#039; followed by a return to make the application logic run:
&lt;pre lang=&quot;csharp&quot;&gt;
static void Main(string[] args)
{
  if (args.Length &gt; 0 &amp;&amp; args[0].ToLower() == &quot;/console&quot;)
  {
	AllocConsole();

    EventLoggerApp app = new EventLoggerApp();
    bool keepRunning = true;
	string input = string.Empty;
	
	Console.WriteLine(&quot;Eventlogger Console started. Type one of the following commands:&quot;);
    Console.WriteLine(&quot;- run: to execute the application logic once manually;&quot;);
    Console.WriteLine(&quot;- scheduled: to execute the application according to the schedule;&quot;);
    Console.WriteLine(&quot;- exit: to exit the application.&quot;);

	// Wait for the user to exit the application                
    while (keepRunning)
    {
      input = Console.ReadLine();

      switch (input.ToLower())
      { 
        case &quot;run&quot;:
          app.RunOnce();
          break;
        case &quot;scheduled&quot;:
          app.Start();
          break;
        case &quot;exit&quot;:
          keepRunning = false;
          break;
      }
    }

    // Stop the application.
    app.Stop();
  }
  else
  {
    // Initialize and run the service
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[] { new EventLoggerService() };
    ServiceBase.Run(ServicesToRun);
  }
}&lt;/pre&gt;

I hope this helps, let me know if you have more questions.

Cheers, Mauri</description>
		<content:encoded><![CDATA[<p>Hi CSDull,</p>
<p>I am glad you found the tutorial helpful.</p>
<p>In remark to your questions there are several solutions of course. Below I will try to give a possible example solution (the full source can be found <a href="http://blog.themobilebrand.com/wp-content/uploads/2012/01/EventLogger-Scheduled.zip" title="Scheduled version of the EventLogger" target="_blank" rel="nofollow">here</a>, Note: I have upgraded the solution to Visual Studio 2008)</p>
<p>First add a new constructor to the &#8216;EventLoggerApp&#8217; which will initialize the &#8216;EventLog&#8217; class and remove the code from the &#8216;Start()&#8217; method, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> EventLoggerApp<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// Check if the EventLoggerService Event Log Source exists, when not</span>
  <span style="color: #008080; font-style: italic;">// create it</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>EventLog<span style="color: #008000;">.</span><span style="color: #0000FF;">SourceExists</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;EventLoggerSource&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    EventLog<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateEventSource</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;EventLoggerSource&quot;</span>, <span style="color: #666666;">&quot;Event Logger&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  _log <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> EventLog<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _log<span style="color: #008000;">.</span><span style="color: #0000FF;">Source</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;EventLoggerSource&quot;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>New &#8216;Start()&#8217; method will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  _thread <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Thread<span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ThreadStart<span style="color: #008000;">&#40;</span>Execute<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The next step is to modify the &#8216;Execute()&#8217; method to run according to a schedule, an example solution could look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Execute<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// Loop until the thread gets aborted</span>
  <span style="color: #0600FF; font-weight: bold;">try</span>
  <span style="color: #008000;">&#123;</span>
    DateTime startTime <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">default</span><span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #6666cc; font-weight: bold;">double</span> intervalInMinutes <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>ConfigurationManager<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;StartTime&quot;</span><span style="color: #008000;">&#93;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> startTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
	  _log<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteEntry</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ERROR (EventLoggerApp.Execute): Unable to parse start date as datetime, check configuration.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	  <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>ConfigurationManager<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;IntervalInMinutes&quot;</span><span style="color: #008000;">&#93;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> intervalInMinutes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
	  _log<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteEntry</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ERROR (EventLoggerApp.Execute): Unable to parse interval as integer, check configuration.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	  <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	DateTime nextRunDate <span style="color: #008000;">=</span> startTime<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
	  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>nextRunDate<span style="color: #008000;">.</span><span style="color: #0000FF;">CompareTo</span><span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
	  <span style="color: #008000;">&#123;</span>
	    <span style="color: #008080; font-style: italic;">// Call the RunOnce method to execute the application logic</span>
		RunOnce<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Calculate the next time to run</span>
		nextRunDate <span style="color: #008000;">=</span> nextRunDate<span style="color: #008000;">.</span><span style="color: #0000FF;">AddMinutes</span><span style="color: #008000;">&#40;</span>intervalInMinutes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	  <span style="color: #008000;">&#125;</span>
&nbsp;
	  <span style="color: #008080; font-style: italic;">// Sleep for ten seconds</span>
	  Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">10000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>ThreadAbortException<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    _log<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteEntry</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;INFO (EventLoggerApp.Execute): Thread aborted.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Next add the &#8216;RunOnce()&#8217; method to the &#8216;EventLoggerApp&#8217; like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> RunOnce<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// TODO: Put you application logic here (like create the log entry in the eventlogger example)</span>
  _log<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteEntry</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;INFO (EventLoggerApp.Execute): Current time is: {0}.&quot;</span>, DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;HH:mm:ss&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The last thing to do is to add an Application Configuration File to the project and add the &#8216;StartTime&#8217; and &#8216;IntervalInMinutes&#8217; settings like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;StartTime&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;14:00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;IntervalInMinutes&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;720&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now to run the application manually you can simply run it from the Command Line. And by changing the &#8216;Program&#8217; class a little we can simple type &#8216;run&#8217; followed by a return to make the application logic run:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&amp;&amp;</span> args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/console&quot;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
	AllocConsole<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    EventLoggerApp app <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> EventLoggerApp<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">bool</span> keepRunning <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #6666cc; font-weight: bold;">string</span> input <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
&nbsp;
	Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Eventlogger Console started. Type one of the following commands:&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;- run: to execute the application logic once manually;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;- scheduled: to execute the application according to the schedule;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;- exit: to exit the application.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Wait for the user to exit the application                </span>
    <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>keepRunning<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      input <span style="color: #008000;">=</span> Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>input<span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span> 
        <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;run&quot;</span><span style="color: #008000;">:</span>
          app<span style="color: #008000;">.</span><span style="color: #0000FF;">RunOnce</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
          <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;scheduled&quot;</span><span style="color: #008000;">:</span>
          app<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
          <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;exit&quot;</span><span style="color: #008000;">:</span>
          keepRunning <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
          <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Stop the application.</span>
    app<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">else</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Initialize and run the service</span>
    ServiceBase<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> ServicesToRun<span style="color: #008000;">;</span>
    ServicesToRun <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ServiceBase<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">new</span> EventLoggerService<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
    ServiceBase<span style="color: #008000;">.</span><span style="color: #0000FF;">Run</span><span style="color: #008000;">&#40;</span>ServicesToRun<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>I hope this helps, let me know if you have more questions.</p>
<p>Cheers, Mauri</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by CSDull33</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-253</link>
		<dc:creator>CSDull33</dc:creator>
		<pubDate>Tue, 24 Jan 2012 20:07:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-253</guid>
		<description>This tutorial was very helpful but I have one question. Like Chetana, I want my service to run twice a day, but would also like the functionality to have it run on demand on occasions. Do you have any suggestion on how I might implement this?</description>
		<content:encoded><![CDATA[<p>This tutorial was very helpful but I have one question. Like Chetana, I want my service to run twice a day, but would also like the functionality to have it run on demand on occasions. Do you have any suggestion on how I might implement this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by William Seaward</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-252</link>
		<dc:creator>William Seaward</dc:creator>
		<pubDate>Sun, 22 Jan 2012 12:04:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-252</guid>
		<description>I loved your article and thank you very much for writting it. Are you still considering updating this  with the addition of reading from the configuration file?</description>
		<content:encoded><![CDATA[<p>I loved your article and thank you very much for writting it. Are you still considering updating this  with the addition of reading from the configuration file?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by Ahmed</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-248</link>
		<dc:creator>Ahmed</dc:creator>
		<pubDate>Tue, 10 Jan 2012 06:10:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-248</guid>
		<description>Really amazing tutorial thanks. I was a little lost on where to start but this was really great. Thanks

I did get some errors

&quot;The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.&quot;

Looks like a permission thing but not sure on where to look</description>
		<content:encoded><![CDATA[<p>Really amazing tutorial thanks. I was a little lost on where to start but this was really great. Thanks</p>
<p>I did get some errors</p>
<p>&#8220;The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.&#8221;</p>
<p>Looks like a permission thing but not sure on where to look</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by TilakG</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-246</link>
		<dc:creator>TilakG</dc:creator>
		<pubDate>Wed, 28 Dec 2011 07:32:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-246</guid>
		<description>Nice tutorial. Any body can create the windows service after reading this tutorial.
I need more details about the window service to incorporate a windows application as a service with the interactive mode and loggings.</description>
		<content:encoded><![CDATA[<p>Nice tutorial. Any body can create the windows service after reading this tutorial.<br />
I need more details about the window service to incorporate a windows application as a service with the interactive mode and loggings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by Jose</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-245</link>
		<dc:creator>Jose</dc:creator>
		<pubDate>Fri, 16 Dec 2011 19:12:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-245</guid>
		<description>Great tutorial. Superior to other alternatives in the internet as of Dec 2011. I would also definitly buy a book about windows services if you wrote it like this.</description>
		<content:encoded><![CDATA[<p>Great tutorial. Superior to other alternatives in the internet as of Dec 2011. I would also definitly buy a book about windows services if you wrote it like this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by Prof g</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-243</link>
		<dc:creator>Prof g</dc:creator>
		<pubDate>Thu, 08 Dec 2011 19:21:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-243</guid>
		<description>Very nicely done Mauri...you have gift for teaching.   Very easy to read, follow.  Look forward to seeing more of your work on the web.

Prof g</description>
		<content:encoded><![CDATA[<p>Very nicely done Mauri&#8230;you have gift for teaching.   Very easy to read, follow.  Look forward to seeing more of your work on the web.</p>
<p>Prof g</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Tutorial &#8211; Building a Windows Service application in C# by mvanbeusekom</title>
		<link>http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/comment-page-1/#comment-242</link>
		<dc:creator>mvanbeusekom</dc:creator>
		<pubDate>Wed, 30 Nov 2011 12:41:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.themobilebrand.com/?p=79#comment-242</guid>
		<description>Hi Neeraj,

Thank you for the nice comments. 

To answer your question, a Windows Service application doesn&#039;t have a UI layer since the process is run on the background. This means you cannot use the standard methods to show a messagebox as you would when building a WinForms application for instance. However there are some possibilities to get some interaction going, maybe you will find these links useful:
&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx&quot; rel=&quot;nofollow&quot;&gt;http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://www.codeguru.com/forum/showthread.php?t=238942&quot; rel=&quot;nofollow&quot;&gt;http://www.codeguru.com/forum/showthread.php?t=238942&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
		<content:encoded><![CDATA[<p>Hi Neeraj,</p>
<p>Thank you for the nice comments. </p>
<p>To answer your question, a Windows Service application doesn&#8217;t have a UI layer since the process is run on the background. This means you cannot use the standard methods to show a messagebox as you would when building a WinForms application for instance. However there are some possibilities to get some interaction going, maybe you will find these links useful:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx</a></li>
<li><a href="http://www.codeguru.com/forum/showthread.php?t=238942" rel="nofollow">http://www.codeguru.com/forum/showthread.php?t=238942</a></li>
</ul>
]]></content:encoded>
	</item>
</channel>
</rss>

