<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sanketik &#187; C#</title>
	<atom:link href="http://blog.sanketik.com/index.php/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sanketik.com</link>
	<description>Next Generation Technology Blog</description>
	<lastBuildDate>Mon, 09 Jan 2012 07:33:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Total instances running of application in C# .NET</title>
		<link>http://blog.sanketik.com/index.php/total-instances-running-of-application-in-c-net/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=total-instances-running-of-application-in-c-net</link>
		<comments>http://blog.sanketik.com/index.php/total-instances-running-of-application-in-c-net/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 15:31:00 +0000</pubDate>
		<dc:creator>Sanket</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Number of instances running]]></category>
		<category><![CDATA[Processes]]></category>

		<guid isPermaLink="false">http://blog.sanketik.com/index.php/total-instances-running-of-application-in-c-net/</guid>
		<description><![CDATA[Total number of instances running of application in C# .NET Many times we needs to find how many instances of particular application or process are running. This can be used in allowing to run only single instance of application or at most 2 etc. Also count can be useful for licensing and other stuff. So [...]]]></description>
			<content:encoded><![CDATA[<h2>Total number of instances running of application in C# .NET</h2>
<p>Many times we needs to find how many instances of particular application or process are running.</p>
<p>This can be used in allowing to run only single instance of application or at most 2 etc.</p>
<p>Also count can be useful for licensing and other stuff.</p>
<p>So here is simple code to find out how many number of instances are running for particular application or process.</p>
<blockquote>
<pre style="font-family: consolas;">    <span style="color: blue;">string</span> fileName = <span style="color: #2b91af;">Process</span>.GetCurrentProcess().MainModule.FileName;</pre>
<pre style="font-family: consolas;">    <span style="color: blue;">int</span> count = 0;</pre>
<pre style="font-family: consolas;">    <span style="color: blue;">foreach</span> (<span style="color: #2b91af;">Process</span> p <span style="color: blue;">in</span> <span style="color: #2b91af;">Process</span>.GetProcesses())</pre>
<pre style="font-family: consolas;">    {</pre>
<pre style="font-family: consolas;">        <span style="color: blue;">try</span></pre>
<pre style="font-family: consolas;"><span style="color: blue;"> </span>        {</pre>
<pre style="font-family: consolas;">            <span style="color: blue;">if</span> (p.MainModule.FileName == fileName)</pre>
<pre style="font-family: consolas;">            {</pre>
<pre style="font-family: consolas;">                count++;</pre>
<pre style="font-family: consolas;">            }</pre>
<pre style="font-family: consolas;">        }</pre>
<pre style="font-family: consolas;">        <span style="color: blue;">catch</span> { }</pre>
<pre style="font-family: consolas;">    }

    <span style="color: #2b91af;">MessageBox</span>.Show(<span style="color: #a31515;">"Total Instances Running are "</span> + count);</pre>
</blockquote>
<p>If you want to do anything additional to this and not aware how to do then please post comment and wait for reply !!!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sanketik.com/index.php/total-instances-running-of-application-in-c-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

