<?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; Uncategorized</title>
	<atom:link href="http://luisguerrero.net/blog/category/uncategorized/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>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>2687</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>2791</slash:comments>
<enclosure url="http://www.luisguerrero.net/Videos/Silverlight4LOB/Sesion01.wmv" length="86648423" type="video/asf" />
		</item>
		<item>
		<title>Como implementar un Singleton concurrente</title>
		<link>http://luisguerrero.net/blog/2009/05/23/como-implementar-un-singleton-concurrente/</link>
		<comments>http://luisguerrero.net/blog/2009/05/23/como-implementar-un-singleton-concurrente/#comments</comments>
		<pubDate>Sat, 23 May 2009 12:33:22 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[concurrent]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[monitor.enter]]></category>
		<category><![CDATA[readerwirterlock]]></category>

		<guid isPermaLink="false">http://luisguerrero.net/?p=78</guid>
		<description><![CDATA[Bajo este título se encuentra una de los clásicos problemas de concurrencia que seguramente más de uno se haya enfrentado en su vida de programador. En este artículo repasaremos las posibles implementaciones correctas e incorrectas de este patrón de manera concurrente. Implementación sin concurrencia. 1: public class Singleton&#60;T&#62; where T : new() 2: { 3: [...]]]></description>
			<content:encoded><![CDATA[<p>Bajo este título se encuentra una de los clásicos problemas de concurrencia que seguramente más de uno se haya enfrentado en su vida de programador. En este artículo repasaremos las posibles implementaciones correctas e incorrectas de este patrón de manera concurrente.</p>
<h3>Implementación sin concurrencia.</h3>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> Singleton&lt;T&gt; <span style="color: #0000ff;">where</span> T : <span style="color: #0000ff;">new</span>()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> T instance = <span style="color: #0000ff;">new</span> T();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> T Instance</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span>             <span style="color: #0000ff;">return</span> instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  11:</span> }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  12:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> SingletonV2&lt;T&gt; <span style="color: #0000ff;">where</span> T : <span style="color: #0000ff;">new</span>()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  13:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  14:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> T instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  15:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> T Instance</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  16:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  17:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  18:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  19:</span>             <span style="color: #0000ff;">if</span> (instance == <span style="color: #0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  20:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  21:</span>                 instance = <span style="color: #0000ff;">new</span> T();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  22:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  23:</span>             <span style="color: #0000ff;">return</span> instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  24:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  25:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  26:</span> }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  27:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> CacheManager</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  28:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  29:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> CacheManager instance = <span style="color: #0000ff;">new</span> CacheManager();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  30:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> CacheManager Instance</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  31:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  32:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  33:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  34:</span>             <span style="color: #0000ff;">return</span> instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  35:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  36:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  37:</span>     <span style="color: #0000ff;">private</span> CacheManager()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  38:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  39:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  40:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  41:</span> }</pre>
</div>
</div>
<p>Como se puede ver esta es la implementación para una clase cualquiera y de una manera genérica, en la que el único requisito que pedimos es que sea una referencia y se pueda construir una instancia.</p>
<p>El problema de estas dos implementaciones es que cuando se construye el tipo se inicializa el valor del Singleton, lo que puede resultar en una degradación del rendimiento y solamente se desea implementar cuando se vaya a acceder al valor de la instancia. Para solucionar ese problema se puede implementar un Singleton perezoso que solamente cuando se accede la primera vez se inicializa.</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> CacheManagerV2</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> CacheManagerV2 instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> CacheManagerV2 Instance</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span>             <span style="color: #0000ff;">if</span> (instance == <span style="color: #0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span>                 instance = <span style="color: #0000ff;">new</span> CacheManagerV2();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  11:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  12:</span>             <span style="color: #0000ff;">return</span> instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  13:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  14:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  15:</span>     <span style="color: #0000ff;">private</span> CacheManagerV2()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  16:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  17:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  18:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  19:</span> }</pre>
</div>
</div>
<p>Pero llegado a este punto nos encontramos con un problema muy importante, que pasa si dos Threads a la vez intenta acceder al valor de la instancia de cualquiera de nuestros Singletones, el resultado puede ser catastrófico, porque se puede iniciar más de una instancia de la clase o cada uno de los Threas se puede llevar una referencia distinta del singleton haciendo que trabajen con instancias diferentes.</p>
<h2>¿Cómo se puede solucionar este problema?</h2>
<p>Hay varias maneras de solucionarlo, la primera de todas sería usar un bloqueo para sincronizar el acceso a este recurso. Vamos a ver una serie de ejemplos y porque estos ejemplos están bien o mal implementados.</p>
<h3>Utilizando bloqueos</h3>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> BadCacheManager</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span>   <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> BadCacheManager instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span>   <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">object</span> syncRoot = <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span>   <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> BadCacheManager Instance</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span>   {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span>       get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span>       {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span>           S0</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span>           <span style="color: #0000ff;">if</span> (instance == <span style="color: #0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  11:</span>           {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  12:</span>               S1</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  13:</span>               <span style="color: #0000ff;">lock</span> (syncRoot)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  14:</span>               {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  15:</span>                   instance = <span style="color: #0000ff;">new</span> BadCacheManager();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  16:</span>               }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  17:</span>           }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  18:</span>           <span style="color: #0000ff;">return</span> instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  19:</span>       }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  20:</span>   }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  21:</span>   <span style="color: #0000ff;">private</span> BadCacheManager()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  22:</span>   {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  23:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  24:</span>   }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  25:</span> }</pre>
</div>
</div>
<h3>BadCacheManager: Mal</h3>
<p>Esta implementacion no funcionaría porque puede darse la casualizad de que durante la primera comprobación (S0) y justo antes de que se instancie la clase (S1) puede haber una instrucción y puede darse la casualidad de que se interrumpa el thread (t0) justo en ese instante, lo que otro thread (t1) evaluaria S0 (true, es nulo) adquiriría el bloqueo pero esperaría (t1) porque el otro thread (t0) lo tiene asignado, así que t0 se despertaría crearia el objeto, después t1 haría lo mismo dando como resultado dos instancias. Además de todo esto no se sincroniza el almacenamiento de la variable instance con un memory barrier (fence) marcando la variable como volatile o usando Thread.MemoryBarrier().</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> DoubleLockVolatileCacheManager</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">volatile</span> DoubleLockVolatileCacheManager instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">object</span> syncRoot = <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> DoubleLockVolatileCacheManager Instance</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span>             <span style="color: #0000ff;">if</span> (instance == <span style="color: #0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  11:</span>                 <span style="color: #0000ff;">lock</span> (syncRoot)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  12:</span>                 {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  13:</span>                     <span style="color: #0000ff;">if</span> (instance == <span style="color: #0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  14:</span>                     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  15:</span>                         instance = <span style="color: #0000ff;">new</span> DoubleLockVolatileCacheManager();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  16:</span>                     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  17:</span>                 }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  18:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  19:</span>             <span style="color: #0000ff;">return</span> instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  20:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  21:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  22:</span>     <span style="color: #0000ff;">private</span> DoubleLockVolatileCacheManager()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  23:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  24:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  25:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  26:</span> }</pre>
</div>
</div>
<h3>DoubleLockVolatileCacheManager: Bien *</h3>
<p>Esta implementación esta bien pero a medias, en la implementacion de .NET el CLR se asegura que independientemente del tipo de reordenacion del procesador, del modelo de memoria y de la atomicidad de las lecturas y escrituras siempre funciona, de hecho es lo que .net utiliza internamente para asegurarse que el constructor estatico (cctor) de un tipo solamente se ejecute una vez. Pero el modelo de memoria de .NET permite reordenaciones de lectura/escritura de variables no volatiles, así que habría que haber marcado la instancia como volatie o insertar un Thread.MemoryBarrier, aquí tenemos la implementacion correcta.</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> DoubleLockCacheManager</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span>    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> DoubleLockCacheManager instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span>    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">object</span> syncRoot = <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span>    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> DoubleLockCacheManager Instance</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span>    {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span>        get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span>        {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span>            <span style="color: #0000ff;">if</span> (instance == <span style="color: #0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span>            {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  11:</span>                <span style="color: #0000ff;">lock</span> (syncRoot)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  12:</span>                {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  13:</span>                    <span style="color: #0000ff;">if</span> (instance == <span style="color: #0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  14:</span>                    {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  15:</span>                        DoubleLockCacheManager tmp = <span style="color: #0000ff;">new</span> DoubleLockCacheManager();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  16:</span>                        Thread.MemoryBarrier();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  17:</span>                        instance = tmp;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  18:</span>                    }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  19:</span>                }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  20:</span>            }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  21:</span>            <span style="color: #0000ff;">return</span> instance;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  22:</span>        }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  23:</span>    }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  24:</span>    <span style="color: #0000ff;">private</span> DoubleLockCacheManager()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  25:</span>    {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  26:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  27:</span>    }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  28:</span> }</pre>
</div>
</div>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> BadLazy&lt;T&gt;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span>   <span style="color: #0000ff;">private</span> T internalValue;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span>   <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">bool</span> isInitialized;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span>   <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">object</span> syncRoot = <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span>   <span style="color: #0000ff;">private</span> Func&lt;T&gt; factory;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span>   <span style="color: #0000ff;">public</span> BadLazy(Func&lt;T&gt; factory)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span>   {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  11:</span>       <span style="color: #0000ff;">this</span>.factory = factory;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  12:</span>   }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  13:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  14:</span>   <span style="color: #0000ff;">public</span> T Value</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  15:</span>   {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  16:</span>       get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  17:</span>       {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  18:</span>           <span style="color: #0000ff;">lock</span> (syncRoot)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  19:</span>           {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  20:</span>               <span style="color: #0000ff;">if</span> (!isInitialized)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  21:</span>               {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  22:</span>                   internalValue = factory();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  23:</span>                   isInitialized = <span style="color: #0000ff;">true</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  24:</span>               }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  25:</span>           }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  26:</span>           <span style="color: #0000ff;">return</span> internalValue;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  27:</span>       }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  28:</span>   }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  29:</span> }</pre>
</div>
</div>
<p>Todos los ejemplos que hemos utilizado aquí utilizan lock (aka Monitor.Enter) para implementar un sistema de bloqueo en los recursos compartidos del Singleton, pero lo ideal para casi todos los casos es no utilizar bloqueos.</p>
<p>¿Cómo se puede implementar un algoritmo libre de bloqueos?, la respuesta está en la granularidad de la concurrencia, gruesa o fina. Nosotros queremos granularidad fina para hacer que los Threads estén el menos tiempo en un bloqueo haciendo así que todo el sistema responda mucho mejor. Una granularidad fina es mucho más complicada de implementar pero tiene un mejor rendimiento y respuesta del sistema porque hay menos contención.</p>
<p>Ahora vamos a ver como sería el Singleton perezoso sin bloqueos.</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> Lazy&lt;T&gt; <span style="color: #0000ff;">where</span> T : <span style="color: #0000ff;">class</span>, <span style="color: #0000ff;">new</span>()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span>    <span style="color: #0000ff;">private</span> T <span style="color: #0000ff;">value</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span>    <span style="color: #0000ff;">public</span> T Value</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span>    {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span>        get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span>        {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span>            <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">value</span> == <span style="color: #0000ff;">null</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span>            {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span>                Interlocked.CompareExchange(<span style="color: #0000ff;">ref</span> <span style="color: #0000ff;">value</span>, <span style="color: #0000ff;">new</span> T(), <span style="color: #0000ff;">null</span>);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  11:</span>            }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  12:</span>            <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">value</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  13:</span>        }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  14:</span>    }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  15:</span> }</pre>
</div>
</div>
<p>Como se puede observar se ha simplificado mucho el código y ahora lo único que tenemos es un Interlocked.CompareExchange, en el que se compara el valor de primer argumento con el del último argumento y si son iguales entonces se establece en el primer argumento el valor de segundo parámetro, así que si nuestra instancia es nula entonces se crea la instancia y se establece. Lo interesante de esta forma de implementarlo es que no tenemos que preocuparnos por el modelo de memoria de .net por la reordenación de instrucciones ni por nada, ya que el Interlocked.CompareExchange es atómica a nivel de hardware, es decir nuestro procesador nos asegura que sea instrucción CMPXCHG es atómica.</p>
<p>Como se puede observar la granularidad de este algoritmo es muy fina porque solamente se bloquea en el momento justo de establecer la variable.</p>
<p>Un ejemplo de una granularidad fina en el uso de los bloqueos la podemos observar en la implementación de este diccionario concurrente.</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> ConcurrentDictionary&lt;TKey, TValue&gt; : IDictionary&lt;TKey, TValue&gt;, ICollection&lt;KeyValuePair&lt;TKey, TValue&gt;&gt;, IEnumerable&lt;KeyValuePair&lt;TKey, TValue&gt;&gt;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   2:</span> {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   3:</span>     <span style="color: #0000ff;">private</span> ReaderWriterLock rw = <span style="color: #0000ff;">new</span> ReaderWriterLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   4:</span>     <span style="color: #0000ff;">private</span> Dictionary&lt;TKey, TValue&gt; dic = <span style="color: #0000ff;">new</span> Dictionary&lt;TKey, TValue&gt;();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   5:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">int</span> timeout = -1;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   6:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Add(TKey key, TValue <span style="color: #0000ff;">value</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   7:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   8:</span>         rw.AcquireWriterLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">   9:</span>         <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  10:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  11:</span>             <span style="color: #0000ff;">if</span> (!dic.ContainsKey(key))</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  12:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  13:</span>                 dic.Add(key, <span style="color: #0000ff;">value</span>);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  14:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  15:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  16:</span>         <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  17:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  18:</span>             rw.ReleaseWriterLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  19:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  20:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  21:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  22:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> ContainsKey(TKey key)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  23:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  24:</span>         <span style="color: #0000ff;">bool</span> res = <span style="color: #0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  25:</span>         rw.AcquireReaderLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  26:</span>         <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  27:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  28:</span>             res = dic.ContainsKey(key);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  29:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  30:</span>         <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  31:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  32:</span>             rw.ReleaseReaderLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  33:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  34:</span>         <span style="color: #0000ff;">return</span> res;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  35:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  36:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  37:</span>     <span style="color: #0000ff;">public</span> ICollection&lt;TKey&gt; Keys</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  38:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  39:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  40:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  41:</span>             ICollection&lt;TKey&gt; res = <span style="color: #0000ff;">null</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  42:</span>             rw.AcquireReaderLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  43:</span>             <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  44:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  45:</span>                 Dictionary&lt;TKey, TValue&gt; tmp = <span style="color: #0000ff;">new</span> Dictionary&lt;TKey, TValue&gt;(dic);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  46:</span>                 res = tmp.Keys;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  47:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  48:</span>             <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  49:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  50:</span>                 rw.ReleaseReaderLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  51:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  52:</span>             <span style="color: #0000ff;">return</span> res;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  53:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  54:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  55:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  56:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> Remove(TKey key)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  57:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  58:</span>         <span style="color: #0000ff;">bool</span> res = <span style="color: #0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  59:</span>         rw.AcquireWriterLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  60:</span>         <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  61:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  62:</span>             res = dic.Remove(key);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  63:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  64:</span>         <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  65:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  66:</span>             rw.ReleaseWriterLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  67:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  68:</span>         <span style="color: #0000ff;">return</span> res;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  69:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  70:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  71:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> TryGetValue(TKey key, <span style="color: #0000ff;">out</span> TValue <span style="color: #0000ff;">value</span>)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  72:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  73:</span>         <span style="color: #0000ff;">bool</span> res = <span style="color: #0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  74:</span>         rw.AcquireWriterLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  75:</span>         <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  76:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  77:</span>             res = dic.TryGetValue(key, <span style="color: #0000ff;">out</span> <span style="color: #0000ff;">value</span>);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  78:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  79:</span>         <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  80:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  81:</span>             rw.ReleaseWriterLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  82:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  83:</span>         <span style="color: #0000ff;">return</span> res;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  84:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  85:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  86:</span>     <span style="color: #0000ff;">public</span> ICollection&lt;TValue&gt; Values</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  87:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  88:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  89:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  90:</span>             ICollection&lt;TValue&gt; res = <span style="color: #0000ff;">null</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  91:</span>             rw.AcquireReaderLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  92:</span>             <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  93:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  94:</span>                 Dictionary&lt;TKey, TValue&gt; tmp = <span style="color: #0000ff;">new</span> Dictionary&lt;TKey, TValue&gt;(dic);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  95:</span>                 res = tmp.Values;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  96:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  97:</span>             <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  98:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;">  99:</span>                 rw.ReleaseReaderLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 100:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 101:</span>             <span style="color: #0000ff;">return</span> res;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 102:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 103:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 104:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 105:</span>     <span style="color: #0000ff;">public</span> TValue <span style="color: #0000ff;">this</span>[TKey key]</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 106:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 107:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 108:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 109:</span>             TValue res = <span style="color: #0000ff;">default</span>(TValue);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 110:</span>             rw.AcquireReaderLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 111:</span>             <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 112:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 113:</span>                 <span style="color: #0000ff;">if</span> (dic.ContainsKey(key))</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 114:</span>                 {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 115:</span>                     res = dic[key];</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 116:</span>                 }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 117:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 118:</span>             <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 119:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 120:</span>                 rw.ReleaseWriterLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 121:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 122:</span>             <span style="color: #0000ff;">return</span> res;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 123:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 124:</span>         set</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 125:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 126:</span>             <span style="color: #0000ff;">if</span> (ContainsKey(key))</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 127:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 128:</span>                 rw.AcquireWriterLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 129:</span>                 <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 130:</span>                 {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 131:</span>                     dic[key] = <span style="color: #0000ff;">value</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 132:</span>                 }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 133:</span>                 <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 134:</span>                 {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 135:</span>                     rw.ReleaseWriterLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 136:</span>                 }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 137:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 138:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 139:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 140:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 141:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 142:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 143:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Add(KeyValuePair&lt;TKey, TValue&gt; item)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 144:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 145:</span>         Add(item.Key, item.Value);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 146:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 147:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 148:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Clear()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 149:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 150:</span>         rw.AcquireWriterLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 151:</span>         <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 152:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 153:</span>             dic.Clear();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 154:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 155:</span>         <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 156:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 157:</span>             rw.ReleaseWriterLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 158:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 159:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 160:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 161:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> Contains(KeyValuePair&lt;TKey, TValue&gt; item)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 162:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 163:</span>         <span style="color: #0000ff;">return</span> ContainsKey(item.Key);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 164:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 165:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 166:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> CopyTo(KeyValuePair&lt;TKey, TValue&gt;[] array, <span style="color: #0000ff;">int</span> arrayIndex)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 167:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 168:</span>         <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> NotImplementedException();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 169:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 170:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 171:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> Count</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 172:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 173:</span>         get</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 174:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 175:</span>             <span style="color: #0000ff;">int</span> count = -1;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 176:</span>             rw.AcquireReaderLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 177:</span>             <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 178:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 179:</span>                 count = dic.Count;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 180:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 181:</span>             <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 182:</span>             {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 183:</span>                 rw.ReleaseReaderLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 184:</span>             }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 185:</span>             <span style="color: #0000ff;">return</span> count;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 186:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 187:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 188:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 189:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> IsReadOnly</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 190:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 191:</span>         get { <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>; }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 192:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 193:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 194:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> Remove(KeyValuePair&lt;TKey, TValue&gt; item)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 195:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 196:</span>         <span style="color: #0000ff;">bool</span> res = <span style="color: #0000ff;">false</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 197:</span>         <span style="color: #0000ff;">if</span> (ContainsKey(item.Key))</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 198:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 199:</span>             Remove(item.Key);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 200:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 201:</span>         <span style="color: #0000ff;">return</span> res;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 202:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 203:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 204:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 205:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 206:</span>     <span style="color: #0000ff;">public</span> IEnumerator&lt;KeyValuePair&lt;TKey, TValue&gt;&gt; GetEnumerator()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 207:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 208:</span>         IEnumerator&lt;KeyValuePair&lt;TKey, TValue&gt;&gt; res = <span style="color: #0000ff;">null</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 209:</span>         rw.AcquireReaderLock(timeout);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 210:</span>         <span style="color: #0000ff;">try</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 211:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 212:</span>             Dictionary&lt;TKey, TValue&gt; tmp = <span style="color: #0000ff;">new</span> Dictionary&lt;TKey, TValue&gt;(dic);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 213:</span>             res = tmp.GetEnumerator();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 214:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 215:</span>         <span style="color: #0000ff;">finally</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 216:</span>         {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 217:</span>             rw.ReleaseReaderLock();</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 218:</span>         }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 219:</span>         <span style="color: #0000ff;">return</span> res;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 220:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 221:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 222:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 223:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 224:</span>     IEnumerator IEnumerable.GetEnumerator()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 225:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 226:</span>         <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 227:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 228:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 229:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 230:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 231:</span>     IEnumerator&lt;KeyValuePair&lt;TKey, TValue&gt;&gt; IEnumerable&lt;KeyValuePair&lt;TKey, TValue&gt;&gt;.GetEnumerator()</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 232:</span>     {</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 233:</span>         <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span>;</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 234:</span>     }</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 235:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 236:</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060;"> 237:</span> }</pre>
</div>
</div>
<p>En el que únicamente cuando se realizan operaciones en el diccionario se intenta bloquear lo menos posible además de que no se utiliza lock (aka Monitor.Enter) sino ReaderWriterLock que permite tener varios lectores y un solo escritor concurrentemente. Se podría haber utilizado ReaderWriterLockSlim que mejora sensiblemente el rendimiento pero esta implementación era para .NET 2.0 y ReaderWriterLockSlim solo funciona con .NET 3.5 además de que en Windows Vista se ha mejorado la implantación nativa.</p>
<p>Os podeis descargar el codigo de ejemplo de aquí</p>
<p><a href="http://www.luisguerrero.net/downloads/Singleton.zip">http://www.luisguerrero.net/downloads/Singleton.zip</a></p>
<p>Espero que os sirva de ayuda.</p>
<p>Saludos. Luis.</p>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2009/05/23/como-implementar-un-singleton-concurrente/feed/</wfw:commentRss>
		<slash:comments>4224</slash:comments>
		</item>
		<item>
		<title>ResourceDictionary y el soporte para Blend en WPF</title>
		<link>http://luisguerrero.net/blog/2008/09/23/resourcedictionary-y-el-soporte-para-blend-en-wpf/</link>
		<comments>http://luisguerrero.net/blog/2008/09/23/resourcedictionary-y-el-soporte-para-blend-en-wpf/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 21:20:16 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.luisguerrero.net/post.aspx?id=14949798-46bd-42e7-9800-86866fe14093</guid>
		<description><![CDATA[La clase ResourceDictionary permite tener un diccionario de recursos para que lo utilicemos en nuestras aplicaciones. Dentro de WPF es normal usar esta clase, ya que como explicamos en otro post anterior (WPF para programadores de Windows Forms 5), estos se pueden sumar o “Merge” con otros diccionarios para tenernos todos centralizados dentro de Application.Current.Resources. [...]]]></description>
			<content:encoded><![CDATA[<p>La clase <a title="ResourceDictionary Class" href="http://msdn2.microsoft.com/ms589726.aspx">ResourceDictionary</a> permite tener un diccionario de recursos para que lo utilicemos en nuestras aplicaciones. Dentro de WPF es normal usar esta clase, ya que como explicamos en otro post anterior (WPF para programadores de Windows Forms 5), estos se pueden sumar o “Merge” con otros diccionarios para tenernos todos centralizados dentro de <a title="Application..::.Resources Property " href="http://msdn2.microsoft.com/ms600307.aspx">Application.Current.Resources</a>.</p>
<p>Esta característica para el soporte te temas (Themes) y para tener en un lugar centralizado los recursos de la aplicación es estupendo, pero si alguna vez has hecho un control con soporte para tiempo de diseño, digamos Visual Studio 2008 o Blend, hacer que esto funcione se puede convertir en un infierno. Veamos porque.</p>
<p>Esta clase Application es una clase implementada como un singleton que gestiona el ciclo de vida de una aplicación WPF, únicamente puede haber una instancia por dominio de aplicación. Imaginemos que por un momento tenemos un código parecido a este. </p>
<div>
<pre><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Collections.Generic;
<span style="color: #0000ff">using</span> System.Linq;
<span style="color: #0000ff">using</span> System.Text;
<span style="color: #0000ff">using</span> System.Windows.Controls;

<span style="color: #0000ff">namespace</span> ApplicationDesingTime
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> MyCustomControl : ContentControl
    {
        <span style="color: #0000ff">public</span> MyCustomControl()
        {
            Template = (ControlTemplate)App.Current.Resources[<span style="color: #006080">&quot;Style1&quot;</span>];
        }
    }
}</pre>
</div>
<p>En el que estamos haciendo un control personalizado que cambia su Template actual para cambiar el árbol visual de controles y tener otro aspecto. Hasta aquí todo bien estamos accediendo al diccionario de recursos que tenemos dentro de nuestra aplicación. Si compilamos y nos llevamos este control que debería de tener este aspecto a blend y lo usamos aparece esto otro.</p>
<p><a target="_blank" href="http://www.luisguerrero.net/Images/ResourceDictionaryyelsoporteparaBlendenW_E9E5/image.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="image" src="http://www.luisguerrero.net/Images/ResourceDictionaryyelsoporteparaBlendenW_E9E5/image_thumb.png" width="304" height="304" /></a> </p>
<p><a target="_blank" href="http://www.luisguerrero.net/Images/ResourceDictionaryyelsoporteparaBlendenW_E9E5/image.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="Blend" src="http://www.luisguerrero.net/Images/ResourceDictionaryyelsoporteparaBlendenW_E9E5/image_thumb.png" width="454" height="345" /></a> </p>
<p>Esto porque ocurre, si ejecutamos la aplicación funciona perfectamente pero si la visualizamos en Blend resulta que no se visualiza correctamente. Es una lástima que tengamos nuestro control, más o menos complejo, pero no podamos verlo en tiempo de diseño. La clave está en la clase <a title="Application Class" href="http://msdn2.microsoft.com/ms588794.aspx">Application</a>. Como antes he comentado la clase Application es única por dominio de aplicación lo que significa que dentro de Blend o Visual Studio existe una clase Application, pero es que resulta que, en el caso de Blend, la clase Application corresponde a la propia aplicación de Blend!!. Esto es un bug o algo así del framework o de Blend, o es que simplemente Blend es un entorno de hosting para nuestros controles y aunque Blend crea instancias de nuestros controles para tiempo de diseño, no es el mismo entorno que cuando se ejecutan.</p>
<p>Y ahora, ¿ya no vamos a tener controles con tiempo de diseño como los que viene con WPF?, claro que sí, pero hay que hacerlo de una manera especial.</p>
<p>Lo primero de todo es que necesitamos alguna manera de saber cuando estamos en blend o cuando estamos ejecutando la aplicación. Esto lo podríamos hacer viendo si el nombre del proceso en el que está mi control es blend.exe, pero si estamos en Visual Studio o en otro programa esto no funcionará, además, WPF tiene una manera más elegante de sabes si estamos en tiempo de diseño o no.</p>
<p>En <a title="System.ComponentModel Namespace" href="http://msdn2.microsoft.com/z82ykwhb.aspx">System.ComponentModel</a> hay una clase <a title="DesignerProperties Class" href="http://msdn2.microsoft.com/aa350307.aspx">System.ComponentModel.DesignerProperties</a> que tiene un método estatico, llamado <a title="DesignerProperties..::.GetIsInDesignMode Method " href="http://msdn2.microsoft.com/aa347321.aspx">GetIsInDesignMode</a> que acepta un <a title="DependencyObject Class" href="http://msdn2.microsoft.com/ms589309.aspx">DependencyObject</a> y te devuelve un booleano que indica si el control está en tiempo de diseño o no. Esto se hace a través de una <a title="DependencyProperty Class" href="http://msdn2.microsoft.com/ms589318.aspx">DependencyProperty</a> atachada que hay en esa clase.</p>
<p>Esta característica también está en Windows Forms, pero a diferencia de Windows Forms, si se consulta esta propiedad en el constructor, esta propiedad está establecida, mientras que en Windows Forms después de crear el objeto el diseñador establece la propiedad de tiempo de diseño.</p>
<p>Ahora que ya sabemos esta información vamos a hacer una clase helper que nos permita acceder a los elementos del ResourceDiccionary desde todos los tiempos.</p>
<div>
<pre><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Collections.Generic;
<span style="color: #0000ff">using</span> System.Linq;
<span style="color: #0000ff">using</span> System.Text;
<span style="color: #0000ff">using</span> System.Windows.Controls;
<span style="color: #0000ff">using</span> System.Windows;

<span style="color: #0000ff">namespace</span> ApplicationDesingTime
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> MyCustomControl : ContentControl
    {
        <span style="color: #0000ff">public</span> MyCustomControl()
        {
            <span style="color: #008000">//Template = (ControlTemplate)App.Current.Resources[&quot;Ejemplo&quot;];</span>
            Template = TemplateHelper.GetData&lt;ControlTemplate&gt;(<span style="color: #0000ff">this</span>, <span style="color: #006080">&quot;Ejemplo&quot;</span>);
        }
    }
}</pre>
</div>
<p><a target="_blank" href="http://www.luisguerrero.net/Images/ResourceDictionaryyelsoporteparaBlendenW_E9E5/image.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="image" src="http://www.luisguerrero.net/Images/ResourceDictionaryyelsoporteparaBlendenW_E9E5/image_thumb_3.png" width="454" height="345" /></a> </p>
<p>Para iniciar un <a title="ResourceDictionary Class" href="http://msdn2.microsoft.com/ms589726.aspx">ResourceDictionary</a> hay que establecer la propiedad <a title="ResourceDictionary..::.Source Property " href="http://msdn2.microsoft.com/ms601225.aspx">Source</a> indicando cual es el fichero .xaml que se va a utilizar como origen de datos. Esta propiedad Source es de tipo <a title="Uri Class" href="http://msdn2.microsoft.com/txt7706a.aspx">Uri</a>, en el que hay que establecer el formato de ensamblado y ruta en un formato especial. </p>
</p>
</p>
</p>
<div>
<pre><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Collections.Generic;
<span style="color: #0000ff">using</span> System.Linq;
<span style="color: #0000ff">using</span> System.Text;
<span style="color: #0000ff">using</span> System.ComponentModel;
<span style="color: #0000ff">using</span> System.Windows;
<span style="color: #0000ff">using</span> System.Diagnostics;

<span style="color: #0000ff">namespace</span> ApplicationDesingTime
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">class</span> TemplateHelper
    {
        <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> ResourceDictionary DesingTimeAppDiccionary;

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> T GetData&lt;T&gt;(DependencyObject context, <span style="color: #0000ff">string</span> name)
        {
            <span style="color: #0000ff">if</span> (DesignerProperties.GetIsInDesignMode(context))
            {
                <span style="color: #0000ff">if</span> (DesingTimeAppDiccionary == <span style="color: #0000ff">null</span>)
                {
                    DesingTimeAppDiccionary = <span style="color: #0000ff">new</span> ResourceDictionary();
                    <span style="color: #0000ff">try</span>
                    {
                        DesingTimeAppDiccionary.Source = <span style="color: #0000ff">new</span> Uri(<span style="color: #006080">&quot;/ApplicationDesingTime;component/Dictionary1.xaml&quot;</span>, UriKind.RelativeOrAbsolute);
                    }
                    <span style="color: #0000ff">catch</span> (Exception ex)
                    {
                        Trace.WriteLine(ex.ToString());
                    }
                }
                <span style="color: #0000ff">return</span> (T)(<span style="color: #0000ff">object</span>)DesingTimeAppDiccionary[name];
            }
            <span style="color: #0000ff">else</span>
            {
                <span style="color: #0000ff">return</span> (T)(<span style="color: #0000ff">object</span>)App.Current.Resources[name];
            }
        }
    }
}</pre>
</div>
<p>El formato de la Uri sería algo así.</p>
<div>
<pre>/{assembly};component/{fichero.xaml}</pre>
</div>
<p>Espero que esto os sirva en los proyectos de WPF que hagais y si haceis muchos controles con tiempo de diseño es interesante este pequeño truco.</p>
<p>Y por cierto si estais pensando en hacer una clase con xaml y un fichero de codigo trasero, hay que tener en cuenta que después esa clase no puede ser la clase base de otro control que esté compuesto de xaml y un fichero .cs así que esta es la mejor manera de modificar el arbol visual de un control para personalizarlo. Pero de eso hablaremos en otro post.</p>
<p>Codigo fuente del post [<a target="_blank" href="http://www.luisguerrero.net/downloads/ApplicationDesingTime.zip">ApplicationDesingTime.zip</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2008/09/23/resourcedictionary-y-el-soporte-para-blend-en-wpf/feed/</wfw:commentRss>
		<slash:comments>2864</slash:comments>
		</item>
		<item>
		<title>Ya esta aqu&iacute; el .net framework 3.5 SP1</title>
		<link>http://luisguerrero.net/blog/2008/05/13/ya-esta-aquiacute-el-net-framework-3-5-sp1/</link>
		<comments>http://luisguerrero.net/blog/2008/05/13/ya-esta-aquiacute-el-net-framework-3-5-sp1/#comments</comments>
		<pubDate>Tue, 13 May 2008 13:47:53 +0000</pubDate>
		<dc:creator>Guerrerotook</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.luisguerrero.net/post.aspx?id=c34b63de-2db9-4542-b77f-00842a00f4d2</guid>
		<description><![CDATA[Hoy ha salido la versi&#243;n beta del .net Framewokr 3.5 SP1, que contiene un monton de mejoras en el framework, y muchos a&#241;adidos que por ahora te podias descargar por separado, las cosas que m&#225;s me parecen interesantes: Mejora del rendimiento del editor de Html de Visual Studio 2008. Francamente el editor de html de [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy ha salido la versi&#243;n beta del .net Framewokr 3.5 SP1, que contiene un monton de mejoras en el framework, y muchos a&#241;adidos que por ahora te podias descargar por separado, las cosas que m&#225;s me parecen interesantes:</p>
<ul>
<li><strong>Mejora del rendimiento del editor de Html de Visual Studio 2008</strong>. Francamente el editor de html de VS2008 es muy bueno, la edici&#243;n de css se ha mejorado mucho, pero el problema es que cuando tienes una pagina asp.net con controles web, cuando haces clic en un control de servidor, por ejemplo un Label, desde el momento en el que pulsas el Label, hasta que en la ventana de propiedades aparecen las propiedades, pueden pasar perfectamente 5 segundos, algo que era un co&#241;azo total.&#160; </li>
<li><strong>Posibilidad de redistribuir una versi&#243;n personalizada del</strong> <strong>framework.</strong> Cuando se desarrollan aplicaciones en .net una de las cosas que siempre hay que tener en cuenta es que el cliente tenga instalado el .net framework en la m&#225;quina de destino, porque sino el software no funciona. En este sentido, Microsoft, tiene muy buenas herramientas para redistribuir su framework tanto en un instalador de msi como desde ClicOnce. Pues ahora con esta mejora puedes hacer una versi&#243;n reducida del .net framework en el que solo se incluyan lo elementos que t&#250; aplciaci&#243;n necesita, haciendo que los tiempos de descarga e instalaci&#243;n sean mejores. Dentro de estas mejoras se encuentra un Bootstrapper, que se encarga de comprobar que tienes la versi&#243;n correcta del framework, y tambi&#233;n mejoras dentro de la publicaci&#243;n con ClicOnce. </li>
</ul>
<p>Dentro de todas las mejoras, las que m&#225;s me interesan de WPF (Windows Presentation Foundation) entre las que encontramos.</p>
<ul>
<li>Animaciones m&#225;s suvaes </li>
<li>Aceleraci&#243;n por hardware de los BitmapsEffects como Blur y DropShadow </li>
<li>Mejoras de rendimiento y velocidad en el renderizado de fuentes </li>
<li>Mejoras en gr&#225;ficos 2D </li>
<li>Una nueva clase WriteableBitmap que permite actualizaci&#243;n de bitmaps al vuelo sin necesidad de generar uno nuevo, al m&#225;s puro estilo&#160; DirectX. </li>
<li>Mejoras en el rendimiento del calculo del Layout </li>
</ul>
<p>&#160;</p>
<p>Y la mejor de todas, que ahora los BitmapsEffects soportan PixelShader. Esto es algo importante porque cuando se programa con WPF, lo efectos de bitmap, est&#225;n prohibidos, &#191;Porqu&#233;? Pues por que cuando a&#241;ades un Bitmap Effect a cualquer elemento, se deshabilita la aceleraci&#243;n por hardware de la aplicaci&#243;n mientras el Bitmap Effect est&#233; dentro del arbol visible, esto ni que decir tiene que es algo muy cutre. </p>
<p>Dentro de la web de ScottGu's Blog <a href="http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx" target="_blank">est&#225;</a> el post describiendo todas las caracter&#237;sticas.</p>
]]></content:encoded>
			<wfw:commentRss>http://luisguerrero.net/blog/2008/05/13/ya-esta-aquiacute-el-net-framework-3-5-sp1/feed/</wfw:commentRss>
		<slash:comments>2771</slash:comments>
		</item>
	</channel>
</rss>

