about

Various. This is about, who I am, what I do and things that are relevant to my interests :¬)

following

robnixon micahbaldwin kevinmann graphicly simplegeo dowding sumogray
Photo

Inception explained for Mac Users
Image from:
http://twitpic.com/2hee34

Inception explained for Mac Users

Image from:

http://twitpic.com/2hee34

Photo

graphicly:

ianbrooks:

geek-art: 8bitmonster: dr-8bit:



The Evolution of Gaming




I can’t wait for Mind Control to come out.

graphicly:

ianbrooks:

geek-art8bitmonsterdr-8bit:

The Evolution of Gaming

I can’t wait for Mind Control to come out.

Link

→ Hey Hey 16K!

Text

WPF 4 & Spellchecking

Using WPF 4?

Want spell checking on your textbox?

BAM: SpellCheck.IsEnabled=”True”

I love it!

Text

Single instance app in WPF 4 with argument passing.

I was building a WPF app that required the use of JumpLists; the thing with JumpLists is that it calls your app’s exe with an argument which in turn creates a new instance of your app.

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.

Only portions of the code was recoverable, the rest I created my self.

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.

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;

    /// <summary>
    /// Occurs when [arguments received].
    /// </summary>
    public event EventHandler<GenericEventArgs<string>> ArgumentsReceived;

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

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

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

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

    /// <summary>
    /// Listens for arguments from successive instances.
    /// </summary>
    public void ListenForArgumentsFromSuccessiveInstances()
    {
      Task.Factory.StartNew(() =>
                              {

                                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();
                                  }
                                }
                              });
    }

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

        ArgumentsReceived(this, new GenericEventArgs<string>() { Data = state.ToString() });
      }
    }
  }
}

Here is the Generic Event Args class

namespace Your.App
{
  using System;

  public class GenericEventArgs<TEventDataType> : EventArgs
  {
    /// <summary>
    /// Gets or sets the data.
    /// </summary>
    /// <value>The data.</value>
    public TEventDataType Data { get; set; }
  }
}

To use this class create an instance with a GUID for your app like so:

private static readonly SingleInstance SingleInstance = new SingleInstance(new Guid("24D910A1-1F03-44BA-85A0-BE7BC2655FFE"));

Then on Application_Startup run your logic for it

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 > 0)
    {
      SingleInstance.PassArgumentsToFirstInstance(e.Args[0]);
    }
	
    Environment.Exit(0);
  }
}

static void SingleInstanceParameter(object sender, GenericEventArgs e)
{
  // Inform app of new arguments
}
Video

Brilliant….

Video

robnixon:

graphicly:

Thanks to Microsoft BizSpark One, here’s a demo of Graphic.ly for Win 7 Mobile from Microsoft Mix 2010!

I’m with Kevin, you can almost see Tony’s nose hairs!

Photo

No question really&#8230;.

source: http://thisisindexed.com/2010/03/fantasy-league/

No question really….

source: http://thisisindexed.com/2010/03/fantasy-league/

Text

Want the directory of a .Net app?

Then use this line:

AppDomain.CurrentDomain.BaseDirectory

Link

→ likes 28 Weeks Later on Boxee

Page 1 of 2