David

  • About Me
  • GoGetter for Windows Phone 7
  • My Etsy Shop
  • Random
  • Archive
  • RSS
  • Ask me anything

Painter's algorithm

Reading up on the Painter’s algorithm. It is used to draw overlapping figures onto one another. First by drawing the farthest items first then drawing up the z-index to the nearest item last.

    • #painter's algorithm
    • #algorithms
    • #algorithms
    • #programming
    • #c
  • 2 months ago
  • Comments
  • Permalink
  • Share

Mutex Snippet for Windows Phone 7

I created a little snippet for my app called “Surround with Mutex”. Basically it protects any call to the isolated storage with a Mutex.

A Mutex is: “A synchronization primitive that can also be used for interprocess synchronization.”

http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx

I had to use this due to my foreground and background agent possibly making calls at the same time to my files within isolated storage. If you do not protect your calls with a Mutex it is possible you could corrupt the data files within isolated storage. I had help with the Mutex with this bit of code example: http://www.albahari.com/threading/part2.aspx#_Mutex

I then took it for my needs and created a snippet for Visual Studio 2010. I named my snippet file Mutex.snippet. 

It is essentially just an XML document with the code below. Instead of having file named Mutex.xml it needs to be renamed to Mutex.snippet.

<?xml version=”1.0” encoding=”utf-8” ?>

<CodeSnippet Format=”1.0.0” xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”>

  <Header>

    <Title>Surround with Mutex</Title>

    <Author>your name here</Author>

    <Shortcut>smutex</Shortcut>

    <Description>Surround with Mutex</Description>

    <SnippetTypes>

      <SnippetType>Expansion</SnippetType>

      <SnippetType>SurroundsWith</SnippetType>      

    </SnippetTypes>

  </Header>

  <Snippet>

    <Code Language=”CSharp”>

      <![CDATA[

                        // Naming a Mutex makes it available computer-wide. Use a name that’s

                        // unique to your company and application (e.g., include your URL).

                        using (var _mutex = new Mutex(false, “myappmutex-www.yourwebaddress.com”))

                        {

                            // Wait a few seconds if contended, in case another instance

                            // of the program is still in the process of shutting down.

                            if (!_mutex.WaitOne(TimeSpan.FromSeconds(3)))

                            {

                                return;

                            }

                            $selected$ $end$

                        }   

      ]]>

    </Code>

  </Snippet>

</CodeSnippet>

Once this file is created in your project you need to add it to your snippet library. You can do this by going to Tools->Code Snippet Manager… then clicking Import…

Then select the snippet you created “Mutex.snippet”. Once you have done this, your snippet is immediately available for use. I just select the code I would like to surround with the Mutex and press control+K, control+S then I am able to use the snippet I created. 

    • #mutex
    • #c
    • #.net
    • #csharp
    • #programming
    • #asp.net
    • #wp7
    • #wp7dev
    • #windows phone
    • #Windows Phone 7
    • #windowsphone
  • 3 months ago
  • Comments
  • Permalink
  • Share

Exiting a Windows Phone Application Programatically

This is just a helpful tip for those who do Windows Phone development. I had issues on trying to figure out what the best way was to exit my app from the app’s main root page. For a while I just threw an exception such as this:

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)

        {

            base.OnBackKeyPress(e);

            throw new Exception(“Exit Main”);           

        }

It irked me to do this, but it worked and passed Marketplace certification. Well, I was needing to perform some code on the App.xaml.cs level when exiting my app:

private void Application_Closing(object sender, ClosingEventArgs e)

        {

            // Do stuff here

        }

Well, this code was never called due to the exception being thrown from my main page when the back button was pressed. So, I dug in a bit to the NavigationService class and realized I could actually remove all back entries that were on the back stack. Joy! So, this is what I came up with for the OnBackKeyPress event:

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)

        {

            base.OnBackKeyPress(e);

            if (NavigationService.CanGoBack)

                {

                    while (NavigationService.RemoveBackEntry() != null)

                    {

                        NavigationService.RemoveBackEntry();

                    }

                }          

        }

And voila! It worked. The app exited properly and the Application_Closing event was called from App.xaml.cs which allowed me to do some background processing of my app’s data.

Hope this can help any of you.

    • #c
    • #windowsphone
    • #windows phone
    • #Windows Phone 7
    • #silverlight
  • 4 months ago
  • Comments
  • Permalink
  • Share

Abstract modifiers

I learned a new thing today, while talking to my friend through G+. Too lazy to be original on my thoughts on it cause I have to code now. But here is what an abstract modifier is.

“The abstract modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes. Members marked as abstract, or included in an abstract class, must be implemented by classes that derive from the abstract class.”

http://msdn.microsoft.com/en-us/library/sf985hc5.aspx

Easy peasy.

    • #c
    • #.net
    • #csharp
  • 4 months ago
  • Comments
  • Permalink
  • Share

Snippets: String to enumerated values

Useful code I use to convert string values to its enumerated counter parts.       

public static T StringToEnum<T>(string name)

        {

            return (T)Enum.Parse(typeof(T), name, false);

        }

        public static T NumToEnum<T>(int number)

        {

            return (T)Enum.ToObject(typeof(T), number);

        }

    • #c
    • #code
    • #programming
    • #snippets
    • #.net
    • #asp.net
    • #wp7
    • #windows phone
    • #Windows Phone 7
    • #windowsphone
    • #wp7dev
  • 4 months ago
  • Comments
  • Permalink
  • Share

CXXI: Briding the C++ and C# worlds.

CXXI technology seems great. Here is a short summary on what it can do for .Net developers needing to inter-op with C++ 


The short story is that the new CXXI technology allows C#/.NET developers to:

Easily consume existing C++ classes from C# or any other .NET language
Instantiate C++ objects from C#
Invoke C++ methods in C++ classes from C# code
Invoke C++ inline methods from C# code (provided your library is compiled with -fkeep-inline-functions or that you provide a surrogate library)
Subclass C++ classes from C#
Override C++ methods with C# methods
Expose instances of C++ classes or mixed C++/C# classes to both C# code and C++ as if they were native code.

    • #cxxi
    • #mono
    • #c++
    • #c
    • #.net
  • 5 months ago
  • Comments
  • Permalink
  • Share
Working on a basic staff listing page using Silverlight and MVVM. Overkill? Maybe so. This is the before page. Will post the after page and link soon. Stay tuned.
Pop-upView Separately

Working on a basic staff listing page using Silverlight and MVVM. Overkill? Maybe so. This is the before page. Will post the after page and link soon. Stay tuned.

    • #c
    • #silverlight
    • #mvvm
    • #asp.net
    • #.net
    • #programming
    • #developer
  • 6 months ago
  • Comments
  • Permalink
  • Share
Boring code for boring work. zzzzzzzzz Can I work on something more interesting please?!
Pop-upView Separately

Boring code for boring work. zzzzzzzzz Can I work on something more interesting please?!

    • #work
    • #code
    • #silverlight
    • #programming
    • #boring
    • #c
    • #.net
    • #linq
    • #linq to objects
    • #mvvm
  • 6 months ago
  • Comments
  • Permalink
  • Share

Logo

Portrait/Logo

I created an awesome "Getting Things Done" app and I make awesome art.

GoGetter for Windows Phone 7: www.gogetterapp.com
Etsy Shop: davidrodriguez.etsy.com

Me, Elsewhere

  • @davidrodriguez on Twitter
  • Facebook Profile
  • davidarodriguez on Flickr
  • iimmerse on Last.fm
  • My Skype Info
  • Linkedin Profile

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

© 2011 David A. Rodriguez. Effector Theme by Carlo Franco.

Powered by Tumblr