<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>ASH360   ►   360 degrees &#38; beyond</title>
	<atom:link href="http://ash360.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ash360.wordpress.com</link>
	<description></description>
	<lastBuildDate>Fri, 17 Apr 2009 03:03:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ash360.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>ASH360   ►   360 degrees &#38; beyond</title>
		<link>http://ash360.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ash360.wordpress.com/osd.xml" title="ASH360   ►   360 degrees &#38; beyond" />
	<atom:link rel='hub' href='http://ash360.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Ensuring that only a single instance of a C#.NET application is running</title>
		<link>http://ash360.wordpress.com/2009/04/14/ensuring-that-only-a-single-instance-of-a-cnet-application-is-running/</link>
		<comments>http://ash360.wordpress.com/2009/04/14/ensuring-that-only-a-single-instance-of-a-cnet-application-is-running/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 12:18:25 +0000</pubDate>
		<dc:creator>ash360</dc:creator>
				<category><![CDATA[C#.NET]]></category>

		<guid isPermaLink="false">http://ash360.wordpress.com/?p=47</guid>
		<description><![CDATA[I ran into a scenario once were i didn&#8217;t want the user to be able to run more than one instance of a C# application, probably you have seen one setting in VB.NET, where you can make a single instance application, if not you can find that under the project properties then in the application [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ash360.wordpress.com&amp;blog=7211495&amp;post=47&amp;subd=ash360&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I ran into a scenario once were i didn&#8217;t want the user to be able to run more than one instance of a C# application, probably you have seen one setting in VB.NET, where you can make a single instance application, if not you can find that<br />
under the project properties then in the application tab ..</p>
<p><img class="aligncenter" src="http://blogs.lessthandot.com/media/blogs/DesktopDev/SingleInstance.jpg" alt="" width="313" height="322" /><br />
Anyways, this option is not available in Visual C#.NET Project Properties !! and it looks like it have to be done programaticaly, the code that accomplishes this is in the <strong>Microsoft.VisualBasic </strong>namespace, and it can be used in a C# application, so a reference to the <strong>Microsoft.VisualBasic</strong> assembly is required in your C# application.<br />
Another way to accomplish that (single app instance) is searching through the currently running processes for you application process and other processes that were launched form the same .exe file&#8230;<br />
After trying a lot of choices any trying a lot of approaches , i ran into the Mutex class (short for &#8220;mutual exclusion&#8221;) , which is a Class from the <strong>System.Threading</strong> Namespace that can be used to keep processes from interfering with each other, and it requires less lines of code and less execution time.</p>
<p><strong>Mutex Class:</strong><br />
Using the Mutex is a quick and a popular way to ensure only once instance is running , so just create a mutex in your program with a specific name,<br />
here is the code to do this:</p>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">using</span><span style="font-size:10pt;font-family:'Courier New';"> System;</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">using</span><span style="font-size:10pt;font-family:'Courier New';"> System.Collections.Generic;</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">using</span><span style="font-size:10pt;font-family:'Courier New';"> System.Linq;</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">using</span><span style="font-size:10pt;font-family:'Courier New';"> System.Windows.Forms;</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">using</span><span style="font-size:10pt;font-family:'Courier New';"> System.Threading;</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">namespace</span><span style="font-size:10pt;font-family:'Courier New';"> My_Application</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';">{</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:blue;">static</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Program</span></span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span>{</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:gray;">///</span><span style="color:green;"> </span></span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:gray;">///</span><span style="color:green;"> The main entry point for the application.</span></span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:gray;">///</span><span style="color:green;"> </span></span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span>[<span style="color:#2b91af;">STAThread</span>]</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:blue;">static</span> <span style="color:blue;">void</span> </span><span style="font-size:10pt;font-family:'Courier New';">Main</span><span style="font-size:10pt;font-family:'Courier New';">()</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span>{</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:blue;">bool</span> ok;</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:green;">//Create and initializes a new instance of the Mutex class. </span></span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:#2b91af;">Mutex</span> m = <span style="color:blue;">new</span> <span style="color:#2b91af;">Mutex</span>(<span style="color:blue;">true</span>, <span style="color:#a31515;">"My Application"</span>, <span style="color:blue;">out</span> ok);</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:blue;">if</span> (!ok)</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span>{</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>  </span><span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"Another instance is already running!"</span>);</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>  </span><span style="color:blue;">return</span>;</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span>}</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:#2b91af;">Application</span>.Run(<span style="color:blue;">new</span> MyApp_Form());</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:green;">//Use the KeepAlive method of the GC Class
</span></span><span style="font-size:10pt;font-family:'Courier New';"><span> </span><span style="color:#2b91af;">GC</span>.KeepAlive(m);</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span>}</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span> </span>}</span></pre>
<pre class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';">}</span></pre>
<p> </p>
<p>Notes:</p>
<ul>
<li>In the Mutex constructor parameters:<br />
- The first parameter is set to true to give the calling thread initial ownership to the mutex.<br />
- The second parameter is the name of the mutex ( give it a unique name).<br />
- The third parameter is a boolean output variable that indicates if ownership was granted to the calling thread.</li>
<li>The KeepAlive method of the GC(Garbage Collector) Class performs no operation and produces no side effect other than extending the lifetime of the object passed in as a parameter.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ash360.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ash360.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ash360.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ash360.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ash360.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ash360.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ash360.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ash360.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ash360.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ash360.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ash360.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ash360.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ash360.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ash360.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ash360.wordpress.com&amp;blog=7211495&amp;post=47&amp;subd=ash360&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ash360.wordpress.com/2009/04/14/ensuring-that-only-a-single-instance-of-a-cnet-application-is-running/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e36733629591f17faaab1eca2b715380?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">ash360</media:title>
		</media:content>

		<media:content url="http://blogs.lessthandot.com/media/blogs/DesktopDev/SingleInstance.jpg" medium="image" />
	</item>
		<item>
		<title>Java Applet bar-chart &amp; line-chart</title>
		<link>http://ash360.wordpress.com/2009/04/14/java-applet-bar-chart-line-chart/</link>
		<comments>http://ash360.wordpress.com/2009/04/14/java-applet-bar-chart-line-chart/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 15:56:42 +0000</pubDate>
		<dc:creator>ash360</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://ash360.wordpress.com/?p=70</guid>
		<description><![CDATA[Here is a Java applet that allows the user to enter as many numbers as desired and then displays the numbers in either bar-chart or line-chart form (the user&#8217;s values are the heights of the bars or the y-points on the graph). it also allows the user to switch between line and bar graph styles. You need [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ash360.wordpress.com&amp;blog=7211495&amp;post=70&amp;subd=ash360&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a Java applet that allows the user to enter as many numbers as desired and then displays the numbers in either bar-chart or line-chart form (the user&#8217;s values are the heights of the bars or the y-points on the graph). it also allows the user to switch between line and bar graph styles.</p>
<p>You need to download the JFree Chart class libraries first:<br />
<a href="http://sourceforge.net/project/showfiles.php?group_id=15494&amp;package_id=12428">http://sourceforge.net/project/showfiles.php?group_id=15494&amp;package_id=12428</a></p>
<p>You can make use of the following class libraries as well from mindviewinc.com:<br />
<a href="http://www.mindviewinc.com/TIJ4/CodeInstructions.html">http://www.mindviewinc.com/TIJ4/CodeInstructions.html</a></p>
<p>So here is the complete code:</p>
<p> </p>
<pre><span style="color:#3366ff;">import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import net.mindview.util.*;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.Box;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.Locale;
import javax.swing.JOptionPane;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
 
import static net.mindview.util.SwingConsole.*;
public class MyChart extends JApplet  {
  private JButton
    b = new JButton("View Bar-Chart"),
    l = new JButton("View Line-Chart");
 
  private JLabel lbl_Input = new JLabel("Enter Some Numbers(Seperated by a comma) ");
  private JTextField txt_Input = new JTextField(3);
 
 
  public void init()
  {
     lbl_Input.setLabelFor(txt_Input);
  
  JPanel TopPane = new JPanel(new GridLayout(0,1));
  TopPane.add(lbl_Input);
  TopPane.add(txt_Input);
  
  JPanel MiddlePane = new JPanel(new GridLayout(0,1));
  
  
 
  JPanel BottomPane = new JPanel();
  BottomPane.add(b);
  BottomPane.add(l);
  
  b.setSize(50, 50);
  l.setSize(50, 50);
  
  
  JPanel contentPane = new JPanel();
  contentPane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
  contentPane.setLayout(new BorderLayout());
  contentPane.add(TopPane, BorderLayout.NORTH);
  contentPane.add(MiddlePane, BorderLayout.CENTER);
  contentPane.add(BottomPane, BorderLayout.SOUTH);
  setContentPane(contentPane);
  
  add(TopPane, BorderLayout.NORTH);
  add(MiddlePane, BorderLayout.CENTER);
  add(BottomPane, BorderLayout.SOUTH);
 }
 public MyChart()
 {
      b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)  {
    
    String input = "";
    input = txt_Input.getText();
    
   
    
    int counter = 0;
    Scanner scanner = new Scanner(input);
    scanner.useDelimiter(",");
    while(scanner.hasNextInt())
    {
    counter ++; 
    scanner.nextInt();
    
    }
    
    
    int[] numbers = new int[counter];
    
    
    Scanner tempscanner = new Scanner(input);
    tempscanner.useDelimiter(",");
    while(tempscanner.hasNextInt())
     {
     
      for(int i = 0 ; i &lt; counter; i++)
       numbers[i] = tempscanner.nextInt();
       
       
       
     }
    
    
    
    
    
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    
    for(int i = 0 ; i &lt; counter ; i++)
      dataset.setValue(numbers[i], "Numbers", "" + numbers[i] );

    JFreeChart chart = ChartFactory.createBarChart
    ("Bar Chart ","", "", dataset, PlotOrientation.VERTICAL, false,true, false);
    chart.setBackgroundPaint(Color.gray);
    chart.getTitle().setPaint(Color.white);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartFrame Chart_Frame=new ChartFrame("Bar Chart",chart);
    Chart_Frame.setVisible(true);
    Chart_Frame.setSize(400,350);
    
  
  
  
  
       }
    });
 
 
 
       l.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)  {
    
    String input = "";
    input = txt_Input.getText();
    
   
    
    int counter = 0;
    Scanner scanner = new Scanner(input);
    scanner.useDelimiter(",");
    while(scanner.hasNextInt())
    {
    counter ++; 
    scanner.nextInt();
    
    }
    
    
    int[] numbers = new int[counter];
    
    
    Scanner tempscanner = new Scanner(input);
    tempscanner.useDelimiter(",");
    while(tempscanner.hasNextInt())
     {
     
      for(int i = 0 ; i &lt; counter; i++)
       numbers[i] = tempscanner.nextInt();
       
       
       
     }
    
    
    
    
    
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    
    for(int i = 0 ; i &lt; counter ; i++)
      dataset.setValue(numbers[i], "Numbers", "" + numbers[i] );
            JFreeChart chart = ChartFactory.createLineChart
      ("Line Chart","", "", dataset, PlotOrientation.VERTICAL, false, true, false );
    
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.black);
    
    
 
    ChartFrame Chart_Frame=new ChartFrame("Line Chart",chart);
    Chart_Frame.setVisible(true);
    Chart_Frame.setSize(400,350);
  
  
  
  
       }
    });
 
 
 
 
 
}
 public static void main(String[] args) {
    run(new MyChart(), 400, 200);
  }
  public static void run(JApplet applet, int width, int height) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(applet);
    frame.setSize(width, height);
    applet.init();
    applet.start();
    frame.setVisible(true);
  }
}</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ash360.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ash360.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ash360.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ash360.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ash360.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ash360.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ash360.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ash360.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ash360.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ash360.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ash360.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ash360.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ash360.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ash360.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ash360.wordpress.com&amp;blog=7211495&amp;post=70&amp;subd=ash360&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ash360.wordpress.com/2009/04/14/java-applet-bar-chart-line-chart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e36733629591f17faaab1eca2b715380?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">ash360</media:title>
		</media:content>
	</item>
	</channel>
</rss>
