<?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>Luis Guerrero &#187; Silverlight</title>
	<atom:link href="http://luisguerrero.net/blog/category/silverlight/feed/" rel="self" type="application/rss+xml" />
	<link>http://luisguerrero.net</link>
	<description>Hablando de .NET, Silverlight, WPF, Windows Phone 7 y depuración</description>
	<lastBuildDate>Tue, 31 Jan 2012 19:55:01 +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>Como implementar TemplateSelector en el ListBox de Windows Phone 7</title>
		<link>http://luisguerrero.net/blog/2011/05/02/como-implementar-templateselector-en-el-listbox-de-windows-phone-7/</link>
		<comments>http://luisguerrero.net/blog/2011/05/02/como-implementar-templateselector-en-el-listbox-de-windows-phone-7/#comments</comments>
		<pubDate>Mon, 02 May 2011 17:48:45 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[DataTemplate]]></category>
		<category><![CDATA[TemplateSelector]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/blog/2011/05/02/como-implementar-templateselector-en-el-listbox-de-windows-phone-7/</guid>
		<description><![CDATA[Si solo has trabajando con Silverlight nunca has conocido el TemplateSelector de WPF, que como su nombre indica permite hacer un selector por discriminador para las plantillas de datos. En el caso que nos atañe ListBox, tiene una propiedad llamada ItemTemplate en la que se establece la plantilla de datos para cada uno de los [...]]]></description>
			<content:encoded><![CDATA[<p>Si solo has trabajando con Silverlight nunca has conocido el TemplateSelector de WPF, que como su nombre indica permite hacer un selector por discriminador para las plantillas de datos. En el caso que nos atañe ListBox, tiene una propiedad llamada ItemTemplate en la que se establece la plantilla de datos para cada uno de los ítems.</p>
<p>¿Para qué se puede querer cambiar la plantilla?</p>
<p>Imaginaros el escenario de estar haciendo una aplicación para mostrar una lista de noticias provenientes de un rss, podemos tener una plantilla para las noticias con imágenes, otra plantilla para las noticias sin imágenes y además podemos querer una plantilla especial para una noticia destacada. Este tipo de escenario que es el más común es bastante difícil de conseguir con Silverlight puesto que no tiene TemplateSelector.</p>
<p>Para conseguir esta funcionalidad tenemos que implementarlo a mano. </p>
<p>Hay varias maneras de llegar hasta esta aproximación la que desde mi punto de vista es la más adecuada es crear un ListBox personalizado, porque nos permite tener toda la funcionalidad y aspecto existente del ListBox pero con el selector de plantillas.</p>
<p>El proceso de creación de un ListBox personalizado se hace en dos partes, la primera se tiene que hacer una clase que herede de ListBox. En esta clase, que llamaremos DataTemplateListBox, tenemos que sobrescribir dos métodos virtuales:</p>
<ul>
<li><b>GetContainerForItemOverride</b>: este método devuelve un objeto que será el ítem container que el ListBox usará para alojar los ítems que se establezcan en el ItemSource. En el caso del ListBox, la implementación predeterminada de este método devuelve un ListBoxItem que es el contenedor predeterminado del ListBox. En nuestro ejemplo tenemos que generar un ListBoxItem personalizado que tendrá la funcionalidad de establecer el DataTemplate. </li>
<li><b>PrepareContainerForItemOverride</b>: Este método es llamado cuando el ListBox está a punto de empezar a hacer la pasada de Layout, y es el momento justo para establecer el código de nuestros discriminador. Este método acepta dos parámetros, uno llamado element de tipo DependencyObject que es el contenedor del ListBox, y el otro ítem de tipo object que es el objeto que nosotros estamos estableciendo al ListBox. </li>
</ul>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> DataTemplateListBox : ListBox
{
    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> DependencyObject GetContainerForItemOverride()
    {
        <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> DataTemplateListBoxItem();
    }
    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> PrepareContainerForItemOverride(DependencyObject element, <span style="color: #0000ff">object</span> item)
    {
        <span style="color: #0000ff">base</span>.PrepareContainerForItemOverride(element, item);
        DataTemplateListBoxItem lbi = (DataTemplateListBoxItem)element;
        <span style="color: #0000ff">if</span> (item <span style="color: #0000ff">is</span> News)
        {
            News newItem = (News)item;
            <span style="color: #0000ff">if</span> (!newItem.IsHighLighted)
            {
                lbi.CustomTemplate = (DataTemplate)App.Current.Resources[<span style="color: #006080">&quot;NewsDataTemplate&quot;</span>];
            }
            <span style="color: #0000ff">else</span>
            {
                lbi.CustomTemplate = (DataTemplate)App.Current.Resources[<span style="color: #006080">&quot;HighLightedNewsDataTemplate&quot;</span>];
            }
        }
    }
}</pre>
</div>
<p>Como hemos dicho anteriormente en el proceso de creación del ListBox tenemos que crear también un ListBoxItem que será el contenedor neutro que tendrá una propiedad de tipo DataTemplate, que será el DataTemplate usado para dibujar ese elemento con una plantilla especifica.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">[TemplatePart(Name = <span style="color: #006080">&quot;DisplayContent&quot;</span>, Type = <span style="color: #0000ff">typeof</span>(ContentControl))]
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> DataTemplateListBoxItem : ListBoxItem
{
    <span style="color: #cc6633">#region</span> Properties

    <span style="color: #0000ff">public</span> DataTemplate CustomTemplate
    {
        get { <span style="color: #0000ff">return</span> (DataTemplate)GetValue(CustomTemplateProperty); }
        set { SetValue(CustomTemplateProperty, <span style="color: #0000ff">value</span>); }
    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">readonly</span> DependencyProperty CustomTemplateProperty =
        DependencyProperty.Register(
            <span style="color: #006080">&quot;CustomTemplate&quot;</span>,
            <span style="color: #0000ff">typeof</span>(DataTemplate),
            <span style="color: #0000ff">typeof</span>(DataTemplateListBoxItem),
            <span style="color: #0000ff">new</span> PropertyMetadata(<span style="color: #0000ff">null</span>));

    <span style="color: #cc6633">#endregion</span>

    <span style="color: #cc6633">#region</span> Constructors
    <span style="color: #0000ff">public</span> CategoryItemsListBoxItem()
    {
        DefaultStyleKey = <span style="color: #0000ff">typeof</span>(DataTemplateListBoxItem);
    }
    <span style="color: #cc6633">#endregion</span>
}</pre>
</div>
<p>Este es el código de ejemplo de un DataTemplateListBoxItem, pero también necesitamos generar un estilo predeterminado que contenga un elemento de tipo ContentControl que será el elemento que tendrá la interfaz del usuario del elemento.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">&lt;</span><span style="color: #800000">Style</span> <span style="color: #ff0000">TargetType</span><span style="color: #0000ff">=&quot;controls:DataTemplateListBoxItem&quot;</span> <span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Setter</span> <span style="color: #ff0000">Property</span><span style="color: #0000ff">=&quot;Template&quot;</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">Setter.Value</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">ControlTemplate</span> <span style="color: #ff0000">TargetType</span><span style="color: #0000ff">=&quot;controls:DataTemplateListBoxItem&quot;</span><span style="color: #0000ff">&gt;</span>
                <span style="color: #0000ff">&lt;</span><span style="color: #800000">ContentControl</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;DisplayContent&quot;</span> <span style="color: #ff0000">Content</span><span style="color: #0000ff">=&quot;{TemplateBinding DataContext}&quot;</span>
                                <span style="color: #ff0000">ContentTemplate</span><span style="color: #0000ff">=&quot;{TemplateBinding CustomTemplate}&quot;</span>  <span style="color: #0000ff">/&gt;</span>
            <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ControlTemplate</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Setter.Value</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Setter</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">Style</span><span style="color: #0000ff">&gt;</span></pre>
</div>
<p>Como se puede apreciar en el código xaml lo que se hace es agregar a la plantilla un ControlTemplate y en ese ControlTemplate se establecen dos propiedades Content con un binding de plantilla (TemplateBinding) a la propiedad DataContext, con eso conseguirnos establecer el objeto como contenido y que se dibuje. La otra propiedad que falta por establecer es justamente la propiedad ContentTemplate que en este caso se hace lo mismo, hacer un binding de plantilla con la propiedad CustomTemplate que es de la clase DataTemplateListBoxItem.</p>
<p>Ahora lo que tenemos que hacer es insertar nuestro DataTemplateListBox en el control MainPage y enlazarle un ViewModel con datos para mostrar un par de noticias generadas por código:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">&lt;</span><span style="color: #800000">Grid</span> <span style="color: #ff0000">x:Name</span><span style="color: #0000ff">=&quot;ContentPanel&quot;</span> <span style="color: #ff0000">Grid</span>.<span style="color: #ff0000">Row</span><span style="color: #0000ff">=&quot;1&quot;</span><span style="color: #0000ff">&gt;</span>
   <span style="color: #0000ff">&lt;</span><span style="color: #800000">DataTemplateDemo_Controls:DataTemplateListBox</span> <span style="color: #ff0000">ItemsSource</span><span style="color: #0000ff">=&quot;{Binding Items}&quot;</span><span style="color: #0000ff">/&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">Grid</span><span style="color: #0000ff">&gt;</span></pre>
</div>
<p>Con eso conseguimos tener un ListBox en el nosotros decidimos en cada uno de los elementos como queremos aplicarle una plantilla de datos. Este es el resultado:</p>
<p><a href="http://luisguerrero.net/wp-content/uploads/2011/05/image.png" target="_blank"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://luisguerrero.net/wp-content/uploads/2011/05/image_thumb.png" width="268" height="484" /></a></p>
<p>La demo no es muy impresionante en sí, pero permite tener la flexibilidad de poder elegir elemento por elemento cual es la plantilla que vamos a usar de manera programática. </p>
<p>La demo completa la podéis descargar de <a href="http://www.luisguerrero.net/downloads/DataTemplateDemo.zip">aquí</a>.</p>
<p>Luis Guerrero.</p>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2011/05/02/como-implementar-templateselector-en-el-listbox-de-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>816</slash:comments>
		</item>
		<item>
		<title>Gesti&#243;n de proxies de WCF en Silverlight 4</title>
		<link>http://luisguerrero.net/blog/2011/04/02/gestin-de-proxies-de-wcf-en-silverlight-4/</link>
		<comments>http://luisguerrero.net/blog/2011/04/02/gestin-de-proxies-de-wcf-en-silverlight-4/#comments</comments>
		<pubDate>Sat, 02 Apr 2011 17:12:10 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[ProxyFactory]]></category>
		<category><![CDATA[ProxyManager]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=197</guid>
		<description><![CDATA[Una de las cosas que más esfuerzo me cuestan cuanto estoy desarrollando aplicaciones en Silverlight es la gestión del ciclo de vida de un proxy de WCF, es decir, crear la instancia del proxy con la configuración del binding correcta, subscribirme a los eventos complete de las operaciones que quiero invocar y en caso de [...]]]></description>
			<content:encoded><![CDATA[<p>Una de las cosas que más esfuerzo me cuestan cuanto estoy desarrollando aplicaciones en Silverlight es la gestión del ciclo de vida de un proxy de WCF, es decir, crear la instancia del proxy con la configuración del binding correcta, subscribirme a los eventos complete de las operaciones que quiero invocar y en caso de falta en el proxy volver a hacer todo ese trabajo, de-subscribirme de los eventos complete y volver a repetir el proceso de nuevo. </p>
<p>Es por eso que en el día a día del desarrollo de aplicaciones de Silverlight siempre intento hacer que las cosas sean muy fáciles para mí y que pueda manejar el ciclo de vida de un proxy de una manera muy cómoda. Viendo un poco cuales son las limitaciones que tengo con los proxy de wcf, me encuentro con las que he comentado anteriormente:</p>
<ul>
<li>Creación del proxy con la configuración del binding adecuada. </li>
<li>Invocación asíncrona de las operaciones </li>
<li>Ciclo de vida del proxy </li>
</ul>
<p>La primera de las limitaciones se soluciona de manera fácil, con una factoría. Una clase helper o factoría que me permita instancias los proxy de manera cómoda con un sistema centralizado de configuración de bindings y demás opciones. Normalmente en un proyecto de Silverlight casi todos los proxy, por no decir todos, serán del mismo tipo, así que no tenemos que preocuparnos mucho por dar soporte a varios tipos de configuraciones.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ProxyFactory
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> T CreateInstance&lt;T, K&gt;(Uri uri)
        <span style="color: #0000ff">where</span> K : <span style="color: #0000ff">class</span>
        <span style="color: #0000ff">where</span> T : ClientBase&lt;K&gt;
    {
        T result = <span style="color: #0000ff">default</span>(T);

        CustomBinding custom = <span style="color: #0000ff">new</span> CustomBinding();
        custom.Elements.Add(<span style="color: #0000ff">new</span> BinaryMessageEncodingBindingElement());
        custom.Elements.Add(<span style="color: #0000ff">new</span> HttpTransportBindingElement()
        {
            MaxReceivedMessageSize = 2147483647,
            MaxBufferSize = 2147483647
        });
        SetDebugTimeouts(custom);

        EndpointAddress address = <span style="color: #0000ff">new</span> EndpointAddress(uri.ToString());

        result = (T)(<span style="color: #0000ff">object</span>)Activator.CreateInstance(<span style="color: #0000ff">typeof</span>(T), custom, address);

        <span style="color: #0000ff">return</span> result;
    }

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> SetDebugTimeouts(CustomBinding custom)
    {
        <span style="color: #0000ff">if</span> (custom != <span style="color: #0000ff">null</span>)
        {
            TimeSpan timeout = TimeSpan.FromSeconds(60 * 3);
            timeout = TimeSpan.MaxValue;
            custom.CloseTimeout = timeout;
            custom.OpenTimeout = timeout;
            custom.ReceiveTimeout = timeout;
            custom.SendTimeout = timeout;
        }
    }
}</pre>
</div>
<p>Aquí tenemos el código de la factoría de proxy.</p>
<p>Si nos fijamos acepta dos parámetros genéricos, que son: K es la interfaz del contrato del canal de comunicaciones es decir el contrato de operaciones y T es la clase que hereda de ServiceBase&lt;K&gt;, es decir la clase que implementa el contrato de operaciones en cliente. </p>
<p>Así de esta manera en el cuerpo de la creación podemos crear a mano un custombinding y añadir los elementos que necesitamos, como por ejemplo: BinaryMessageEncondingBindingElement y HttpTransportBindingElement, además de configurar parámetros de esas clases. Creamos también una instancia de la clase EndpointAddress que contiene la dirección url del servicio wcf. </p>
<p>Una vez que tenemos todo esto podemos utilizar la clase Activator para crear una instancia dinámicamente del proxy (a través del tipo de T) pasándoles los parámetros previamente establecidos.</p>
<p>Para consumir el proxy sería de esta manera:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">KeyPlayerServiceClient proxy =
ProxyFactory.CreateInstance&lt;KeyPlayerServiceClient, IKeyPlayerService&gt;(ProxyUrl.KeyPlayerUrl);</pre>
</div>
<p>Así podemos tener un sistema centralizado de creación de todos los proxies que queramos consumir desde Silverlight.</p>
<h3>Manejar el resultado y el ciclo de vida</h3>
<p>Pero esta manera de crear las instancias no soluciona el problema que tenemos de manejar el ciclo de vida del proxy, subscribirnos al evento complete de la operación y obtener el resultado de la operación. Es por eso que necesitamos una clase que nos permita invocar una operación asíncrona de un servicio web y que de alguna manera esa clase helper, cree la instancia de la clase, se subscriba al evento de complete, obtenga el resultado de la operación y llame a un delegado que nosotros le hemos especificado. Esto sería lo ideal.</p>
<p>Pues bien podemos hacer todo eso de manera cómoda con esta clase ProxyManager. Antes de centrarnos en cuál es la implementación concreta de la clase y los detalles vamos a ver cómo podemos consumir una operación típica de un servicio de wcf con esta clase ProxyManager.</p>
<p>Si tenemos un servicio con esta operación:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">[ServiceContract]
<span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IServiceDemo
{
   [OperationContract]
   DateTime GetDateTime();
}</pre>
</div>
<p>Tenemos una única operación que se llama GetDateTime y que obtenemos un objeto de tipo DateTime.</p>
<p>Una vez que hemos agregado la referencia al proxy de WCF desde nuestro proyecto de Silverlight, podemos hacer esto:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">// manera directa de invocar un servicio web y solo centrarse en la respuesta segun su tipo</span>
ProxyManager&lt;ServiceDemoClient, IServiceDemo&gt; manager = <span style="color: #0000ff">new</span> ProxyManager&lt;ServiceDemoClient, IServiceDemo&gt;(ProxyUrl.DemoService);
<span style="color: #008000">// como sabemos que el servicio web devuelve un resultado de tipo DateTime, podemos</span>
<span style="color: #008000">// agregar un Action&lt;DateTime&gt; porque DAteTiem es el tipo de devuelve</span>
manager.InvokeOperation&lt;DateTime, GetDateTimeCompletedEventArgs&gt;(
    <span style="color: #006080">&quot;GetDateTime&quot;</span>,
    <span style="color: #0000ff">new</span> Action&lt;DateTime&gt;(OnGetDateTimeCompleted),
    <span style="color: #0000ff">null</span>);
<span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> OnGetDateTimeCompleted(DateTime dateTime)
{
}</pre>
</div>
<p>En este ejemplo fijaros que utilizando la genericidad y la reflexión podemos hacer que la invocación del servicio sea mucho más cómoda, podemos resumirlo a una simple línea de código.</p>
<h3>Requisitos tiene la clase ProxyManager</h3>
<p>Para crear una instancia de la clase ProxyManager tenemos que pasar los mismos argumentos de tipos que el ProxyFactory, de hecho internamente utiliza el mismo mecanismo, además de la uri de la dirección del servicio web.</p>
<p>Una vez que tenemos el objeto creado tenemos que llamar al único método de la clase ProxyManager, InvokeOperation.</p>
<p>InvokeOperation acepta dos parámetros de tipo que son el tipo que devuelve la operación del servicio web, si nos acordamos era un DateTime, y el otro parámetro genérico es la clase que hereda de AsyncCompletedEventArgs que contiene el resultado de la invocación, en nuestro ejemplo, GetDateTimeCompletedEventArgs. De esta clase es donde el ProxyManager obtendrá el resultado de la operación.</p>
<p>Como parámetros de la función tenemos que suplir el nombre de la operación como un string, en nuestro caso GetDateTime (pero sin Async al final), después un delegado de tipo Action&lt;T&gt; con el resultado, y al final de todos los parámetros un array de tipo object con la palabra params que son los argumentos de la invocación, en nuestro caso null. </p>
<p>Lo bueno que tiene esta clase ProxyManager es que automáticamente por nosotros crea la instancia del proxy, se subscribe al evento complete de la operación que queremos invocar y automáticamente invoca nuestro delegado de tipo Action&lt;T&gt; con el resultado, además de eso cuando termina la invocación del objeto de tipo Action&lt;T&gt; se de-subscribe del evento y cierra el proxy. Toda una gozada.</p>
<p>Además de eso tenemos la posibilidad de utilizar una sobrecarga de la función InvokeOperation que nos permite tener también acceso al objeto de UserState de la invocación por si invocamos más de una vez la operación y necesitamos acceder a un objeto de usuario en la devolución de llamada:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #008000">// manera directa de invocar un servicio web y solo centrarse en la respuesta segun su tipo</span>
ProxyManager&lt;ServiceDemoClient, IServiceDemo&gt; manager = <span style="color: #0000ff">new</span> ProxyManager&lt;ServiceDemoClient, IServiceDemo&gt;(ProxyUrl.DemoService);
<span style="color: #008000">// como sabemos que el servicio web devuelve un resultado de tipo DateTime, podemos</span>
<span style="color: #008000">// agregar un Action&lt;DateTime&gt; porque DAteTiem es el tipo de devuelve</span>
manager.InvokeOperation&lt;DateTime, GetDateTimeCompletedEventArgs&gt;(
    <span style="color: #006080">&quot;GetDateTime&quot;</span>,
    <span style="color: #0000ff">new</span> Action&lt;DateTime&gt;(OnGetDateTimeCompleted),
    <span style="color: #0000ff">null</span>);

manager.InvokeOperation&lt;DateTime, <span style="color: #0000ff">object</span>, GetDateTimeCompletedEventArgs&gt;(
    <span style="color: #006080">&quot;GetDateTime&quot;</span>,
    <span style="color: #0000ff">new</span> Action&lt;DateTime, <span style="color: #0000ff">object</span>&gt;(OnGetDateTimeWithArgumentsCompleted),
    <span style="color: #0000ff">null</span>);
<span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> OnGetDateTimeWithArgumentsCompleted(DateTime result, <span style="color: #0000ff">object</span> userState)
{

}</pre>
</div>
<p>Con esto podemos hacer que la gestión de los proxies de WCF sea mucho más eficiente que cómoda para el programador que antes.</p>
<p>Codigo fuente completo de la clase ProxyManager:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.ComponentModel;
<span style="color: #0000ff">using</span> System.Linq;
<span style="color: #0000ff">using</span> System.Reflection;
<span style="color: #0000ff">using</span> System.ServiceModel;

<span style="color: #0000ff">namespace</span> ViewModelBinding.Services
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ProxyManager&lt;TService, KServiceInterface&gt;
        <span style="color: #0000ff">where</span> KServiceInterface : <span style="color: #0000ff">class</span>
        <span style="color: #0000ff">where</span> TService : ClientBase&lt;KServiceInterface&gt;
    {
        <span style="color: #0000ff">public</span> ProxyManager(Uri url)
        {
            proxy = ProxyFactory.CreateInstance&lt;TService, KServiceInterface&gt;(url);
        }

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> InvokeOperation&lt;TResult, KEventArgs&gt;(<span style="color: #0000ff">string</span> operationName, Action&lt;TResult&gt; action, <span style="color: #0000ff">params</span> <span style="color: #0000ff">object</span>[] args)
            <span style="color: #0000ff">where</span> KEventArgs : AsyncCompletedEventArgs
        {
            <span style="color: #0000ff">if</span> (!<span style="color: #0000ff">string</span>.IsNullOrWhiteSpace(operationName))
            {
                InternalActionOf&lt;KEventArgs, TResult&gt; internalAction = <span style="color: #0000ff">new</span> InternalActionOf&lt;KEventArgs, TResult&gt;(action);
                internalAction.EventInfo = proxy.GetType().GetEvent(<span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0}Completed&quot;</span>, operationName));
                internalAction.Delegate = <span style="color: #0000ff">new</span> EventHandler&lt;KEventArgs&gt;(internalAction.OnActionExecuted);
                internalAction.EventInfo.AddEventHandler(proxy, internalAction.Delegate);
                internalAction.Proxy = proxy;

                <span style="color: #0000ff">if</span> (args == <span style="color: #0000ff">null</span>)
                {
                    args = <span style="color: #0000ff">new</span> <span style="color: #0000ff">object</span>[] { };
                }

                MethodInfo[] methods = proxy.GetType().GetMethods();
                <span style="color: #0000ff">string</span> methodName = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0}Async&quot;</span>, operationName);
                var found = (from p <span style="color: #0000ff">in</span> methods
                             <span style="color: #0000ff">where</span> p.Name == methodName &amp;&amp; p.GetParameters().Length == args.Length
                             select p).FirstOrDefault();

                <span style="color: #0000ff">if</span> (found != <span style="color: #0000ff">null</span>)
                {
                    found.Invoke(proxy, args);
                }
            }
        }

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> InvokeOperation&lt;TResult, TUSerState, KEventArgs&gt;(<span style="color: #0000ff">string</span> operationName, Action&lt;TResult, TUSerState&gt; action, <span style="color: #0000ff">params</span> <span style="color: #0000ff">object</span>[] args)
            <span style="color: #0000ff">where</span> KEventArgs : AsyncCompletedEventArgs
        {
            <span style="color: #0000ff">if</span> (!<span style="color: #0000ff">string</span>.IsNullOrWhiteSpace(operationName))
            {
                InternalActionOf&lt;KEventArgs, TResult, TUSerState&gt; internalAction = <span style="color: #0000ff">new</span> InternalActionOf&lt;KEventArgs, TResult, TUSerState&gt;(action);
                internalAction.EventInfo = proxy.GetType().GetEvent(<span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0}Completed&quot;</span>, operationName));
                internalAction.Delegate = <span style="color: #0000ff">new</span> EventHandler&lt;KEventArgs&gt;(internalAction.OnActionExecuted);
                internalAction.EventInfo.AddEventHandler(proxy, internalAction.Delegate);
                internalAction.Proxy = proxy;

                <span style="color: #0000ff">if</span> (args == <span style="color: #0000ff">null</span>)
                {
                    args = <span style="color: #0000ff">new</span> <span style="color: #0000ff">object</span>[] { };
                }

                MethodInfo[] methods = proxy.GetType().GetMethods();
                <span style="color: #0000ff">string</span> methodName = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0}Async&quot;</span>, operationName);
                var found = (from p <span style="color: #0000ff">in</span> methods
                             <span style="color: #0000ff">where</span> p.Name == methodName &amp;&amp; p.GetParameters().Length == args.Length
                             select p).FirstOrDefault();

                <span style="color: #0000ff">if</span> (found != <span style="color: #0000ff">null</span>)
                {
                    found.Invoke(proxy, args);
                }
            }
        }

        <span style="color: #0000ff">private</span> TService proxy;
    }
}</pre>
</div>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">internal</span> <span style="color: #0000ff">class</span> InternalActionOf&lt;EventArgs, TResult, TUserState&gt;
       <span style="color: #0000ff">where</span> EventArgs : AsyncCompletedEventArgs
{
   <span style="color: #0000ff">public</span> InternalActionOf(Action&lt;TResult, TUserState&gt; action)
   {
       <span style="color: #0000ff">this</span>.action = action;
   }

   <span style="color: #0000ff">internal</span> <span style="color: #0000ff">void</span> OnActionExecuted(<span style="color: #0000ff">object</span> args, EventArgs e)
   {
       PropertyInfo property = e.GetType().GetProperty(<span style="color: #006080">&quot;Result&quot;</span>, BindingFlags.Public | BindingFlags.Instance);
       <span style="color: #0000ff">if</span> (property != <span style="color: #0000ff">null</span>)
       {
           <span style="color: #0000ff">object</span> result = property.GetValue(e, <span style="color: #0000ff">null</span>);
           <span style="color: #0000ff">if</span> (result != <span style="color: #0000ff">null</span>)
           {
               <span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(TResult).IsAssignableFrom(property.PropertyType))
               {
                   action((TResult)result, (TUserState)e.UserState);
                   EventInfo.RemoveEventHandler(Proxy, Delegate);
               }
           }
       }
   }

   <span style="color: #0000ff">public</span> EventHandler&lt;EventArgs&gt; Delegate { get; set; }
   <span style="color: #0000ff">public</span> EventInfo EventInfo { get; set; }
   <span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span> Proxy { get; set; }

   <span style="color: #0000ff">private</span> Action&lt;TResult, TUserState&gt; action;
}</pre>
</div>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">internal</span> <span style="color: #0000ff">class</span> InternalActionOf&lt;EventArgs, TResult&gt;
            <span style="color: #0000ff">where</span> EventArgs : AsyncCompletedEventArgs
{
    <span style="color: #0000ff">public</span> InternalActionOf(Action&lt;TResult&gt; action)
    {
        <span style="color: #0000ff">this</span>.action = action;
    }

    <span style="color: #0000ff">internal</span> <span style="color: #0000ff">void</span> OnActionExecuted(<span style="color: #0000ff">object</span> args, EventArgs e)
    {
        PropertyInfo property = e.GetType().GetProperty(<span style="color: #006080">&quot;Result&quot;</span>, BindingFlags.Public | BindingFlags.Instance);
        <span style="color: #0000ff">if</span> (property != <span style="color: #0000ff">null</span>)
        {
            <span style="color: #0000ff">object</span> result = property.GetValue(e, <span style="color: #0000ff">null</span>);
            <span style="color: #0000ff">if</span> (result != <span style="color: #0000ff">null</span>)
            {
                <span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(TResult).IsAssignableFrom(property.PropertyType))
                {
                    action((TResult)result);
                    EventInfo.RemoveEventHandler(Proxy, Delegate);
                }
            }
        }
    }

    <span style="color: #0000ff">public</span> EventHandler&lt;EventArgs&gt; Delegate { get; set; }
    <span style="color: #0000ff">public</span> EventInfo EventInfo { get; set; }
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span> Proxy { get; set; }

    <span style="color: #0000ff">private</span> Action&lt;TResult&gt; action;
}</pre>
</div>
<p>Luis Guerrero.</p>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2011/04/02/gestin-de-proxies-de-wcf-en-silverlight-4/feed/</wfw:commentRss>
		<slash:comments>3367</slash:comments>
		</item>
		<item>
		<title>Silverlight 4 Metro Training (7/7) Dashboard de administración de eventos</title>
		<link>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/</link>
		<comments>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 18:09:24 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=138</guid>
		<description><![CDATA[Hola a todos! El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material. Silverlight 4 Metron Training, Dashboard de administración de eventos [sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion07.wmv] El resto del material: Module 1: What's new in Siverlight 4 [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Hola a todos!</p>
<p>El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material.</p>
<h1>Silverlight 4 Metron Training,</h1>
<h2>Dashboard de administración de eventos</h2>
<p>[sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion07.wmv]</p>
<p>El resto del material:</p>
<ul>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/">Module 1: What's new in Siverlight 4</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/">Module 2: Event Manager</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/">Module 3: User Registration</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/">Module 4: User Profile</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/">Module 5: Schedule Planner</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/">Module 6: Printing</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/">Module 7: Event Administrator Dashboard</a></li>
</ul>
<p>Código fuente de los Labs <a href="http://www.luisguerrero.net/videos/Silverlight4LOB/Code/SL4LOB_07_Event_Administrator_Dashboard.zip" target="_blank">aquí</a>.</p>
<p>Saludos.</p>
<p>Luis Guerrero.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/feed/</wfw:commentRss>
		<slash:comments>2257</slash:comments>
<enclosure url="http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion07.wmv" length="301838325" type="video/asf" />
		</item>
		<item>
		<title>Silverlight 4 Metro Training (5/7) Programador de tareas</title>
		<link>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/</link>
		<comments>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 18:09:23 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=136</guid>
		<description><![CDATA[Hola a todos! El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material. Silverlight 4 Metron Training, Programador de tareas [sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion05.wmv] El resto del material: Module 1: What's new in Siverlight 4 Module 2: [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Hola a todos!</p>
<p>El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material.</p>
<h1>Silverlight 4 Metron Training,</h1>
<h2>Programador de tareas</h2>
<p>[sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion05.wmv]</p>
<p>El resto del material:</p>
<ul>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/">Module 1: What's new in Siverlight 4</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/">Module 2: Event Manager</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/">Module 3: User Registration</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/">Module 4: User Profile</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/">Module 5: Schedule Planner</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/">Module 6: Printing</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/">Module 7: Event Administrator Dashboard</a></li>
</ul>
<p>Código fuente de los Labs <a href="http://www.luisguerrero.net/videos/Silverlight4LOB/Code/SL4LOB_05_Schedule_Planner.zip" target="_blank">aquí</a>.</p>
<p>Saludos.</p>
<p>Luis Guerrero.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/feed/</wfw:commentRss>
		<slash:comments>4497</slash:comments>
<enclosure url="http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion05.wmv" length="264736325" type="video/asf" />
		</item>
		<item>
		<title>Silverlight 4 Metro Training (6/7) Impresión</title>
		<link>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/</link>
		<comments>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 18:09:23 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=137</guid>
		<description><![CDATA[Hola a todos! El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material. Silverlight 4 Metron Training, Impresión [sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion06.wmv] El resto del material: Module 1: What's new in Siverlight 4 Module 2: Event Manager [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Hola a todos!</p>
<p>El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material.</p>
<h1>Silverlight 4 Metron Training,</h1>
<h2>Impresión</h2>
<p>[sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion06.wmv]</p>
<p>El resto del material:</p>
<ul>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/">Module 1: What's new in Siverlight 4</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/">Module 2: Event Manager</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/">Module 3: User Registration</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/">Module 4: User Profile</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/">Module 5: Schedule Planner</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/">Module 6: Printing</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/">Module 7: Event Administrator Dashboard</a></li>
</ul>
<p>Código fuente de los Labs <a href="http://www.luisguerrero.net/videos/Silverlight4LOB/Code/SL4LOB_06_Printing_the_Schedule.zip" target="_blank">aquí</a>.</p>
<p>Saludos.</p>
<p>Luis Guerrero.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/feed/</wfw:commentRss>
		<slash:comments>3966</slash:comments>
<enclosure url="http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion06.wmv" length="168940980" type="video/asf" />
		</item>
		<item>
		<title>Silverlight 4 Metro Training (4/7) Perfil de usuario</title>
		<link>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/</link>
		<comments>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 18:09:19 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=135</guid>
		<description><![CDATA[Hola a todos! El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material. Silverlight 4 Metron Training, Perfil de usuario [sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion04.wmv] El resto del material: Module 1: What's new in Siverlight 4 Module 2: [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Hola a todos!</p>
<p>El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material.</p>
<h1>Silverlight 4 Metron Training,</h1>
<h2>Perfil de usuario</h2>
<p>[sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion04.wmv]</p>
<p>El resto del material:</p>
<ul>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/">Module 1: What's new in Siverlight 4</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/">Module 2: Event Manager</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/">Module 3: User Registration</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/">Module 4: User Profile</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/">Module 5: Schedule Planner</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/">Module 6: Printing</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/">Module 7: Event Administrator Dashboard</a></li>
</ul>
<p>Código fuente de los Labs <a href="http://www.luisguerrero.net/videos/Silverlight4LOB/Code/SL4LOB_04_User_Profile.zip" target="_blank">aquí</a>.</p>
<p>Saludos.</p>
<p>Luis Guerrero.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/feed/</wfw:commentRss>
		<slash:comments>4350</slash:comments>
<enclosure url="http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion04.wmv" length="92949909" type="video/asf" />
		</item>
		<item>
		<title>Silverlight 4 Metro Training (3/7) Registro de usuario</title>
		<link>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/</link>
		<comments>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 18:09:03 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=134</guid>
		<description><![CDATA[Hola a todos! El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material. Silverlight 4 Metron Training, Registro de usuario [sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion03.wmv] El resto del material: Module 1: What's new in Siverlight 4 Module 2: [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Hola a todos!</p>
<p>El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material.</p>
<h1>Silverlight 4 Metron Training,</h1>
<h2>Registro de usuario</h2>
<p>[sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion03.wmv]</p>
<p>El resto del material:</p>
<ul>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/">Module 1: What's new in Siverlight 4</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/">Module 2: Event Manager</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/">Module 3: User Registration</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/">Module 4: User Profile</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/">Module 5: Schedule Planner</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/">Module 6: Printing</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/">Module 7: Event Administrator Dashboard</a></li>
</ul>
<p>Código fuente de los Labs <a href="http://www.luisguerrero.net/videos/Silverlight4LOB/Code/SL4LOB_03_User_Registration.zip" target="_blank">aquí</a>.</p>
<p>Saludos.</p>
<p>Luis Guerrero.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/feed/</wfw:commentRss>
		<slash:comments>2686</slash:comments>
<enclosure url="http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion03.wmv" length="265041567" type="video/asf" />
		</item>
		<item>
		<title>Silverlight 4 Metro Training (2/7) Gestor de eventos</title>
		<link>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/</link>
		<comments>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 18:08:37 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=133</guid>
		<description><![CDATA[Hola a todos! El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material. Silverlight 4 Metron Training, Gestor de eventos [sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion02.wmv] El resto del material: Module 1: What's new in Siverlight 4 Module 2: [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Hola a todos!</p>
<p>El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material.</p>
<h1>Silverlight 4 Metron Training,</h1>
<h2>Gestor de eventos</h2>
<p>[sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion02.wmv]</p>
<p>El resto del material:</p>
<ul>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/">Module 1: What's new in Siverlight 4</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/">Module 2: Event Manager</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/">Module 3: User Registration</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/">Module 4: User Profile</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/">Module 5: Schedule Planner</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/">Module 6: Printing</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/">Module 7: Event Administrator Dashboard</a></li>
</ul>
<p>Código fuente de los Labs <a href="http://www.luisguerrero.net/videos/Silverlight4LOB/Code/SL4LOB_02_Event_Manager.zip" target="_blank">aquí</a>.</p>
<p>Saludos.</p>
<p>Luis Guerrero.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/feed/</wfw:commentRss>
		<slash:comments>3744</slash:comments>
<enclosure url="http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion02.wmv" length="184197931" type="video/asf" />
		</item>
		<item>
		<title>Silverlight 4 Metro Training (1/7) Que hay de nuevo en Silverlight 4</title>
		<link>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/</link>
		<comments>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 18:07:58 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=124</guid>
		<description><![CDATA[Hola a todos! El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material. Silverlight 4 Metron Training, What’s New in Silverlight 4 [sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion01.wmv] El resto del material: Module 1: What's new in Siverlight 4 [...]]]></description>
			<content:encoded><![CDATA[<p>Hola a todos!</p>
<p>El día 7-8 de abril se celebró una formación de Silverlight 4 del programa Metro de Microsoft que impartí, así que os dejo las grabaciones del evento y el material.</p>
<h1>Silverlight 4 Metron Training,</h1>
<h2>What’s New in Silverlight 4</h2>
<p style="text-align: center;">[sl-media: http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion01.wmv]</p>
<p style="text-align: left;">El resto del material:</p>
<ul>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/">Module 1: What's new in Siverlight 4</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-27-gestor-de-eventos/">Module 2: Event Manager</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-37-registro-de-usuario/">Module 3: User Registration</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-47-perfil-de-usuario/">Module 4: User Profile</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-57-programador-de-tareas/">Module 5: Schedule Planner</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-67-impresion/">Module 6: Printing</a></li>
<li><a href="http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-77-dashboard-de-administracion-de-eventos/">Module 7: Event Administrator Dashboard</a></li>
</ul>
<p>Saludos.</p>
<p>Luis Guerrero.</p>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2010/07/17/silverlight-4-metro-training-17-que-hay-de-nuevo-en-silverlight-4/feed/</wfw:commentRss>
		<slash:comments>2790</slash:comments>
<enclosure url="http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion01.wmv" length="86648423" type="video/asf" />
		</item>
		<item>
		<title>Detectando problemas de memoria con Silverlight</title>
		<link>http://luisguerrero.net/blog/2010/04/30/detectando-problemas-de-memoria-con-silverlight/</link>
		<comments>http://luisguerrero.net/blog/2010/04/30/detectando-problemas-de-memoria-con-silverlight/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 18:54:13 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Depuración]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.luisguerrero.net/post.aspx?id=132f82bd-4433-4d4c-aac6-48b3939dbd7e</guid>
		<description><![CDATA[Hola a todos! Hoy vamos a hablar sobre un memory leak encontrado en Silverlight 4 y reportado en el foro de silverilght.net por el usuario tsheflin. Como sabrás Silverlight está basado en tecnología .net lo que significa que puedes escribir tus aplicaciones en C# o en Visual Basic y tienes todas las cosas buenas de [...]]]></description>
			<content:encoded><![CDATA[<p>Hola a todos!</p>
<p>Hoy vamos a hablar sobre un memory leak encontrado en Silverlight 4 y reportado en el foro de <a href="http://forums.silverlight.net/forums/t/171739.aspx" target="_blank">silverilght.net</a> por el usuario <a href="http://forums.silverlight.net/members/tsheflin.aspx">tsheflin</a>. Como sabrás Silverlight está basado en tecnología .net lo que significa que puedes escribir tus aplicaciones en C# o en Visual Basic y tienes todas las cosas buenas de .net como gestión automática de memoria, recolección de elementos no utilizados y seguridad de tipos</p>
<p>Pero algunas veces algo sale más y aun teniendo la gestión automática de memoria de .net nos podemos encontrar con problemas, es por eso que hoy vamos a ver cómo podemos identificar estos problemas con WinDBG y sos para Silverlight. </p>
<p>Voy a usar como ejemplo el codigo subido por el usuario del foro de Silverlight.net. Puedes descargarlo desde <a href="http://luisguerrero.net/downloads/SilverlightVisualTreeRemovalFail.zip" target="_blank">aquí</a>.</p>
<p>Lo primero de todo necesitamos ejecutar nuestra aplicación en modo release. Esto es importante porque hay pequeñas diferencias entre el modo debug y el release. Una vez que tenemos la aplicación ejecutándose es tiempo de WinDGB.</p>
<p>Si tu navegador es Windows Internet Explorer 8 y estás ejecutándolo sobre Windows 7 o Vista, sabrás que IE ejecuta cada tab en un proceso separado y por eso primero tienes que identificar cual es el proceso de IE que está ejecutando el código, en mi caso es el proceso 7958.</p>
<p>Con WinDBG abierto (puedes descargarlo de <a href="http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx#a" target="_blank">aquí</a>) tienes que ir a File -&gt; Attach to process (F6), y selecciona la id de tu proceso (en mi maquina es 7958), inmediatamente aparecerá en la ventana de salida toda la información básica de depuración. Teniendo en cuenta que nuestra aplicación es una aplicación administrada y WinDBG está diseñado para depurar aplicaciones nativas necesitamos una extensión del depurador para trabajar con aplicaciones administradas. Lo que necesitamos es SOS (Son of Strike) que está localizado en C:\Program Files (x86)\Microsoft Silverlight\4.0.50401.0\sos.dll. Para cada version de silverligh hay una versión de SOS, así que depende de la versión de Silveright que estés depurando tendrás que usar una u otra.</p>
<p>Para cargar SOS escribimos</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">.load C:\Program Files (x86)\Microsoft Silverlight\4.0.50401.0\sos.dll</pre>
</div>
<p>Lo siguiente que necesitamos encontrar es una direccion valida del tipo que estamos buscando SilverlightVisualTreeRemovalFail.SilverlightControl1 y para eso tenemos que usar el comando !dumpheap para volcar todos los tipos filtrados por este tipo.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">!dumpheap -type SilverlightVisualTreeRemovalFail.SilverlightControl1

0:005&gt; !dumpheap -type SilverlightVisualTreeRemovalFail.SilverlightControl1

Address MT Size

087aad6c 04a45230 92

087ab460 04a45230 92

087ab6f0 04a45230 92

087ac01c 04a45230 92

087ac710 04a45230 92

087ace04 04a45230 92

087ad4f8 04a45230 92

087adbec 04a45230 92

087ae2e0 04a45230 92

087ae9d4 04a45230 92

087af0c8 04a45230 92

087af7bc 04a45230 92

087afeb0 04a45230 92

087b05a4 04a45230 92

087b0c98 04a45230 92

087b138c 04a45230 92

087b1a80 04a45230 92

087b2174 04a45230 92

087b2868 04a45230 92

087b2f5c 04a45230 92

087b3650 04a45230 92

087b3d44 04a45230 92

087b4438 04a45230 92

087b4b2c 04a45230 92

087b5220 04a45230 92

087b5914 04a45230 92

087b6008 04a45230 92

087b66fc 04a45230 92

087b6df0 04a45230 92

087b74e4 04a45230 92

087b7bd8 04a45230 92

087b82cc 04a45230 92

087b89c0 04a45230 92

087b90b4 04a45230 92

087b97a8 04a45230 92

087b9e9c 04a45230 92

087ba590 04a45230 92

087bac84 04a45230 92

087bb378 04a45230 92

087bba6c 04a45230 92

087bc160 04a45230 92

087bc854 04a45230 92

087bcf48 04a45230 92

087bd63c 04a45230 92

087bdd30 04a45230 92

087be424 04a45230 92

087beb18 04a45230 92

087bf20c 04a45230 92

087bf900 04a45230 92

087bfff4 04a45230 92</pre>
</div>
<p>En la ventana de salida encontramos direcciones del tipo que hemos solicitado, seleccionamos una <strong>087b1a80</strong> y buscamos que objetos están referenciando este objeto (esto es lo que está causando que el objeto no sea recolectado) escribiendo esto:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">!gcroot 087b1a80

0:005&gt; !gcroot 087b1a80

Note: Roots found on stacks may be <span style="color: #0000ff">false</span> positives. Run <span style="color: #006080">"!help gcroot"</span> <span style="color: #0000ff">for</span>

more info.

Scan Thread 5 OSTHread 10e8

Scan Thread 22 OSTHread 1f8

Scan Thread 23 OSTHread 1588

DOMAIN(07134BE0):HANDLE(Pinned):4a912f8:Root: 09784260(System.Object[])-&gt;

08796c78(System.Collections.Generic.Dictionary`2[[System.IntPtr, mscorlib],[System.Object, mscorlib]])-&gt;

09788260(System.Collections.Generic.Dictionary`2+Entry[[System.IntPtr, mscorlib],[System.Object, mscorlib]][])-&gt;

087b1e90(System.Windows.Controls.ControlTemplate)-&gt;

087b1a80(SilverlightVisualTreeRemovalFail.SilverlightControl1)</pre>
</div>
<p>Encontramos que el objeto (<strong>087b1a80</strong>) está referenciado por otro objeto y en lo alto de la lista podemos encontrar cual es el objeto que lo está referenciando.</p>
<p>Ahora que hemos identificado que el objeto está referenciado por un GCHandle pineado el recolector siempre encontrará un camino hasta este objeto haciendo que nunca sea recolectado. Como el código que controla esta funcionalidad es de Microsoft no podemos hacer nada al respecto, pero en caso de que sea nuestro lo que podemos hacer es simplemente eliminar las referencias para que el objeto sea recolectado. </p>
<p>Además podemos volcar todos los tipos que hay en el heap y abrirlo con el CLRProfiler usando !traverseheap.</p>
<p>Saludos.</p>
<p>Luis Guerrero.</p>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2010/04/30/detectando-problemas-de-memoria-con-silverlight/feed/</wfw:commentRss>
		<slash:comments>3111</slash:comments>
		</item>
	</channel>
</rss>

