<?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>Tony Williams &#187; .Net 4</title>
	<atom:link href="http://blog.tonywilliams.me.uk/tag/net-4/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tonywilliams.me.uk</link>
	<description></description>
	<lastBuildDate>Tue, 10 Jan 2012 12:31:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Clickonce Manifest Problem with .Net 4</title>
		<link>http://blog.tonywilliams.me.uk/clickonce-manifest-problem-with-net-4/</link>
		<comments>http://blog.tonywilliams.me.uk/clickonce-manifest-problem-with-net-4/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 08:49:11 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[.Net 4]]></category>
		<category><![CDATA[ClickOnce]]></category>

		<guid isPermaLink="false">http://blog.tonywilliams.me.uk/?p=43</guid>
		<description><![CDATA[.Net 4.0 Click once manifest problem and how it was resolved.]]></description>
			<content:encoded><![CDATA[<p>This post is a little test with the <a href="http://stackapps.com/questions/518/stacktack-a-javascript-widget-you-can-stick-anywhere">StackTack </a>app. It&#8217;s about my question on <a href="http://stackoverflow.com/questions/2872567/clickonce-manifest-problem ">StackOverflow </a>regarding ClickOnce manifest problem.</p>
<div id="stacktack-2872567"></div>
<p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script src="http://app.stacktack.com/jquery.stacktack.min.js" type="text/javascript">
</script><script type="text/javascript">// <![CDATA[
            $(document).ready(function() {             $(document).stacktack();         });
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonywilliams.me.uk/clickonce-manifest-problem-with-net-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Single instance app in WPF 4 with argument passing</title>
		<link>http://blog.tonywilliams.me.uk/single-instance-app-in-wpf-4-with-argument-passing/</link>
		<comments>http://blog.tonywilliams.me.uk/single-instance-app-in-wpf-4-with-argument-passing/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 13:08:03 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 4]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF 4]]></category>

		<guid isPermaLink="false">http://blog.tonywilliams.me.uk/?p=26</guid>
		<description><![CDATA[How to have a WPF app with only 1 instance with only C# code and argument passing.]]></description>
			<content:encoded><![CDATA[<p>Extracted from: <a href="http://random.tonywilliams.me.uk/post/483779269/single-instance-app-in-wpf-4-with-argument-passing">http://random.tonywilliams.me.uk/post/483779269/single-instance-app-in-wpf-4-with-argument-passing</a></p>
<div>
<p>I was building a WPF app that required the use of JumpLists; the thing with JumpLists is that it calls your app&#8217;s exe with an argument which in turn creates a new instance of your app.</p>
<p>After a quick bit of googling I found a link [now dead] some code that restricts an app to a signle instance by using a mutex and passes the command argument supplied via named pipes.</p>
<p>Only portions of the code was recoverable, the rest I created my self.</p>
<p>Note that the code uses the .Net 4 Tasks, this can be replaced with threads if you want to use it in .Net 3.5. This also only passes the first argument through but can be easily changed to pass multiple.</p>
<pre class="brush:c#">namespace Your.App
{
  using System;
  using System.IO;
  using System.IO.Pipes;
  using System.Threading;
  using System.Threading.Tasks;

  public class SingleInstance : IDisposable
  {
    private readonly bool ownsMutex;
    private Mutex mutex;
    private Guid identifier;

    /// &lt;summary&gt;
    /// Occurs when [arguments received].
    /// &lt;/summary&gt;
    public event EventHandler&lt;GenericEventArgs&lt;string&gt;&gt; ArgumentsReceived;

    /// &lt;summary&gt;
    /// Initializes a new instance of the &lt;see cref="SingleInstance"/&gt; class.
    /// &lt;/summary&gt;
    /// &lt;param name="id"&gt;The id.&lt;/param&gt;
    public SingleInstance(Guid id)
    {
      this.identifier = id;
      mutex = new Mutex(true, identifier.ToString(), out ownsMutex);
    }

    /// &lt;summary&gt;
    /// Gets a value indicating whether this instance is first instance.
    /// &lt;/summary&gt;
    /// &lt;value&gt;
    /// 	&lt;c&gt;true&lt;/c&gt; if this instance is first instance; otherwise, &lt;c&gt;false&lt;/c&gt;.
    /// &lt;/value&gt;
    public bool IsFirstInstance
    {
      get
      {
        return ownsMutex;
      }
    }

    /// &lt;summary&gt;
    /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    /// &lt;/summary&gt;
    public void Dispose()
    {
      if (mutex != null &amp;&amp; ownsMutex)
      {
        mutex.ReleaseMutex();
        mutex = null;
      }
    }

    /// &lt;summary&gt;
    /// Passes the arguments to first instance.
    /// &lt;/summary&gt;
    /// &lt;param name="argument"&gt;The argument.&lt;/param&gt;
    public void PassArgumentsToFirstInstance(string argument)
    {
      using (var client = new NamedPipeClientStream(identifier.ToString()))
      using (var writer = new StreamWriter(client))
      {
        client.Connect(200);
        writer.WriteLine(argument);
      }
    }

    /// &lt;summary&gt;
    /// Listens for arguments from successive instances.
    /// &lt;/summary&gt;
    public void ListenForArgumentsFromSuccessiveInstances()
    {
      Task.Factory.StartNew(() =&gt;
                              {

                                using (var server = new NamedPipeServerStream(identifier.ToString()))
                                using (var reader = new StreamReader(server))
                                {
                                  while (true)
                                  {
                                    server.WaitForConnection();

                                    var argument = string.Empty;
                                    while (server.IsConnected)
                                    {
                                      argument += reader.ReadLine();
                                    }

                                    CallOnArgumentsReceived(argument);
                                    server.Disconnect();
                                  }
                                }
                              });
    }

    /// &lt;summary&gt;
    /// Calls the on arguments received.
    /// &lt;/summary&gt;
    /// &lt;param name="state"&gt;The state.&lt;/param&gt;
    public void CallOnArgumentsReceived(object state)
    {
      if (ArgumentsReceived != null)
      {
        if (state == null)
        {
          state = string.Empty;
        }

        ArgumentsReceived(this, new GenericEventArgs&lt;string&gt;() { Data = state.ToString() });
      }
    }
  }
}</pre>
<p>Here is the Generic Event Args class</p>
<pre class="brush:c#">namespace Your.App
{
  using System;

  public class GenericEventArgs&lt;TEventDataType&gt; : EventArgs
  {
    /// &lt;summary&gt;
    /// Gets or sets the data.
    /// &lt;/summary&gt;
    /// &lt;value&gt;The data.&lt;/value&gt;
    public TEventDataType Data { get; set; }
  }
}</pre>
<p>To use this class create an instance with a GUID for your app like so:</p>
<pre class="brush:c#">private static readonly SingleInstance SingleInstance = new SingleInstance(new Guid("24D910A1-1F03-44BA-85A0-BE7BC2655FFE"));</pre>
<p>Then on Application_Startup run your logic for it</p>
<pre class="brush:c#">private void Application_Startup(object sender, StartupEventArgs e)
{
  if (SingleInstance.IsFirstInstance)
  {
    SingleInstance.ArgumentsReceived += SingleInstanceParameter;
    SingleInstance.ListenForArgumentsFromSuccessiveInstances();
	// Do your other app logic
  }
  else
  {
    // if there is an argument available, fire it
    if (e.Args.Length &gt; 0)
    {
      SingleInstance.PassArgumentsToFirstInstance(e.Args[0]);
    }

    Environment.Exit(0);
  }
}

static void SingleInstanceParameter(object sender, GenericEventArgs e)
{
  // Inform app of new arguments
}</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonywilliams.me.uk/single-instance-app-in-wpf-4-with-argument-passing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with Touch (in .Net 4.0)</title>
		<link>http://blog.tonywilliams.me.uk/working-with-touch-in-net-4-0/</link>
		<comments>http://blog.tonywilliams.me.uk/working-with-touch-in-net-4-0/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 16:42:04 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[.Net 4]]></category>
		<category><![CDATA[Touch]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF 4]]></category>

		<guid isPermaLink="false">http://blog.tonywilliams.me.uk/?p=9</guid>
		<description><![CDATA[Some tips on Touch in .Net 4]]></description>
			<content:encoded><![CDATA[<div>
<p>Extracted from: <a href="http://random.tonywilliams.me.uk/post/745164436/working-with-touch-in-net-4-0">http://random.tonywilliams.me.uk/post/745164436/working-with-touch-in-net-4-0</a></p>
<p>For the past several months I&#8217;ve been hammering away at the <a href="http://graphic.ly/win7/setup.exe">touch app</a> for <a href="http://graphic.ly/">Graphic.ly</a> and I&#8217;ve picked up a few hints and tricks along the way.</p>
<p><strong>The first tip</strong> is to get a decent touch monitor or at least a touch machine that you can develop on. I&#8217;m using the <a href="http://accessories.us.dell.com/sna/productdetail.aspx?c=us&amp;l=en&amp;cs=19&amp;sku=320-1172">Dell SX2210T</a> monitor and couldn&#8217;t be happier; within seconds you&#8217;re ready to do some touch magic!</p>
<p><strong>My second tip</strong> is to use the <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=801907a7-b2dd-4e63-9ff3-8a2e63932a74">Surface Toolkit from Microsoft</a>. This however will limit your app to Windows 7 only where as if you choose to go with other libraries for touch your apps may work in older versions but just not respond to touch.</p>
<p>If you plan to go with this library (and I recommend you do) there here are some helpful links:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ee957351.aspx">MSDN</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/toolkit_mref_reference_home(Surface.15).aspx">API</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.aspx">Controls</a></li>
</ul>
<p>As you can see from the Controls link there are a number of controls to play with; the two that are mainly used in the Graphic.ly app are the <a href="http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacewindow.aspx">SurfaceWindow </a>and<a href="http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacescrollviewer.aspx">SurfaceScrollViewer</a>.</p>
<p>The <em>SurfaceWindow </em>provides UI responses to touch via the <a href="http://msdn.microsoft.com/en-us/library/ee957338.aspx">Touch Visualizations</a> as well as display on a touch monitor in a multi-monitor setup.</p>
<p>The <em>SurfaceScrollViewer </em>simply adds alot of touch magic to the <em>ScrollViewer</em>; anywhere you could use a ScrollViewer then use the <em>SurfaceScrollViewer</em>. There is not much to do in terms of quickly getting touch on your app when you use the control from the toolkit library. In the Graphic.ly app the Store, Collection and Activity Stream are all examples of the <em>SurfaceScrollViewer </em>in action.</p>
<p>The problem I&#8217;m having with the <em>SurfaceScrollViewer </em>is having them nested; if you checkout the Store/Collection you&#8217;ll see I have rows of SurfaceScrollViewers. Swiping back and forth works fine but I just cannot get it to work up and down. Seems to be the child <em>SurfaceScrollViewer </em>handles all the touch events and won&#8217;t pass it along, does this mean nested <em>SufaceScrollViewers </em>will never work? Nope, this just means another touch challenge to conquer <img src='http://blog.tonywilliams.me.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>My 3rd and final tip</strong> (for the moment) is this</p>
<p>&#8220;e.Cancel();&#8221;</p>
<p>If you have hooked up some <em>TouchEvents </em>AND some <em>ManipulationEvents </em>then you&#8217;ll know that the ManipulationEvents prevents the TouchEvents from firing; in other words you can swipe but not press. In the &#8220;<em>ManipulationCompleted</em>&#8221; event I check to see if the change is small enough to consider it not a swipe; &#8220;e.Cancel()&#8221; will cancel this event and let the <em>TouchEvents </em>bubble through.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonywilliams.me.uk/working-with-touch-in-net-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

