Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 864d1c3c3cd8df4e3a2692faf8776e05 > files > 224

db4o-doc-7.4-2.fc13.i686.rpm

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Optimistic Locking</title>
    <link rel="stylesheet" type="text/css" href="../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>Optimistic Locking</h1><script>
//We attach this function to a browser object as a variable so that if multiple of these blocks are
//present on the same page, then they will simply over-write eachother with the same function instead
//of generating a naming collision.
window.WikiCodeFormattingCopyToClipboard = function copyToClipboard(sID){
	var sContent = document.getElementById(sID).innerText;
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", sContent);
	}
	else
	{
		alert("You must enable javascript access to your clipboard for this feature to work. Please referr to your browser documentation or Google search for instructions.");
	}
}
</script><p>In optimistic locking system no locks are used to prevent
collision: any user can read an object into the memory and work on it at any
time. However, before the client can save its modifications back to the database,
a check should take place verifying that the item did not change since the time
of initial read (no collision occurred). If a collision is detected it should
be resolved according to your application logic. Typical solutions are:</p>

<ul><li>Rollback
</li><li>Display the
problem and let the user decide<br> </li><li>Merge the
changes </li><li>Log the
problem so someone can decide later </li><li>Ignore the
collision and overwrite</li></ul>









<p>Let's look at an example realization.</p>

<p>We will use a db4o database containing
objects of Pilot class and a separate thread to create a client connection to
the database, retrieve and modify objects.</p>



<span name="cs_wiki_filter" csw_filters="cs"><div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">OptimisticThread.cs: <span class="fscMemberName">Run</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Run()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_26_2285_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Open_Text').style.display='inline';"/>            </span><span style="color: #0000FF;">try</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_44_2233_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Open_Text').style.display='inline';"/>        </span><span style="color: #0000FF;">while</span><span style="color: #000000;"> (result.HasNext())</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_133_2216_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          Pilot pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Pilot)result.Next();
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Open_Text').style.display='inline';"/>                </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">/**/</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_194_451_Open_Text"><span style="color: #008000;">/*</span><span style="color: #008000;"> We will need to set a lock to make sure that the 
</span><span style="color: #008080;">08</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>           * object version corresponds to the object retrieved.
</span><span style="color: #008080;">09</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>           * (Prevent other client committing changes
</span><span style="color: #008080;">10</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>           * at the time between object retrieval and version
</span><span style="color: #008080;">11</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>           * retrieval )
</span><span style="color: #008080;">12</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>           </span><span style="color: #008000;">*/</span></span><span style="color: #000000;">
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">_container.Ext().SetSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> _container.Ext().GetID(pilot), </span><span style="color: #800080;">3000</span><span style="color: #000000;">))
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Open_Text').style.display='inline';"/>                </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_567_686_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error. The object is locked</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">continue</span><span style="color: #000000;">;
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>                }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                _container.Ext().Refresh(pilot, Int32.MaxValue);
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          </span><span style="color: #0000FF;">long</span><span style="color: #000000;"> objVersion </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Ext().GetObjectInfo(pilot).GetVersion();
</span><span style="color: #008080;">20</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                _container.Ext().ReleaseSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> _container.Ext().GetID(pilot));
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Open_Text').style.display='inline';"/>          </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">/**/</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_928_1147_Open_Text"><span style="color: #008000;">/*</span><span style="color: #008000;"> save object version into _idVersions collection
</span><span style="color: #008080;">22</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>           * This will be needed to make sure that the version
</span><span style="color: #008080;">23</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>           * originally retrieved is the same in the database 
</span><span style="color: #008080;">24</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>           * at the time of modification
</span><span style="color: #008080;">25</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>           </span><span style="color: #008000;">*/</span></span><span style="color: #000000;">
</span><span style="color: #008080;">26</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          </span><span style="color: #0000FF;">long</span><span style="color: #000000;"> id </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Ext().GetID(pilot);
</span><span style="color: #008080;">27</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          _idVersions.Add(id, objVersion);
</span><span style="color: #008080;">28</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          
</span><span style="color: #008080;">29</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Updating pilot: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot</span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> version: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">+</span><span style="color: #000000;">objVersion);
</span><span style="color: #008080;">30</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              pilot.AddPoints(</span><span style="color: #800080;">1</span><span style="color: #000000;">);
</span><span style="color: #008080;">31</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              _updateSuccess </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">;
</span><span style="color: #008080;">32</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              RandomWait();
</span><span style="color: #008080;">33</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Open_Text').style.display='inline';"/>              </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">_container.Ext().SetSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">+</span><span style="color: #000000;">_container.Ext().GetID(pilot), </span><span style="color: #800080;">3000</span><span style="color: #000000;">))</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1526_1630_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">34</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error. The object is locked</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #008080;">35</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">continue</span><span style="color: #000000;">;
</span><span style="color: #008080;">36</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>              }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">37</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              _container.Set(pilot);
</span><span style="color: #008080;">38</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Open_Text').style.display='inline';"/>              </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">/**/</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1680_1783_Open_Text"><span style="color: #008000;">/*</span><span style="color: #008000;"> The changes should be committed to be 
</span><span style="color: #008080;">39</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>               * visible to the other clients
</span><span style="color: #008080;">40</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>               </span><span style="color: #008000;">*/</span></span><span style="color: #000000;">
</span><span style="color: #008080;">41</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              _container.Commit();
</span><span style="color: #008080;">42</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              _container.Ext().ReleaseSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">+</span><span style="color: #000000;">_container.Ext().GetID(pilot));
</span><span style="color: #008080;">43</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Open_Text').style.display='inline';"/>              </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (_updateSuccess)</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_1937_2020_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">44</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Updated pilot: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot);
</span><span style="color: #008080;">45</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>              }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">46</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine();
</span><span style="color: #008080;">47</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Open_Text').style.display='inline';"/>              </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">/**/</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2071_2171_Open_Text"><span style="color: #008000;">/*</span><span style="color: #008000;"> The object version is not valid after commit
</span><span style="color: #008080;">48</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>               * - should be removed
</span><span style="color: #008080;">49</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>               </span><span style="color: #008000;">*/</span></span><span style="color: #000000;">
</span><span style="color: #008080;">50</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              _idVersions.Remove(id);
</span><span style="color: #008080;">51</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>        }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">52</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          
</span><span style="color: #008080;">53</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Open_Text').style.display='inline';"/>      }</span></span><span style="color: #000000;"> </span><span style="color: #0000FF;">finally</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_Run_963_55_2242_2276_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">54</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        _container.Close();
</span><span style="color: #008080;">55</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>      }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">56</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>       }</span></span></div></pre></div></div></span><span name="cs_wiki_filter" csw_filters="vb"><div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">OptimisticThread.vb: <span class="fscMemberName">Run</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Public</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub Run()</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_Run_1070_55_7_2675_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> Run()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">While</span><span style="color: #000000;"> result.HasNext
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> pilot </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(result.Next, Pilot)
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> We will need to set a lock to make sure that the </span><span style="color: #008000;">
</span><span style="color: #008080;">07</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> object version corresponds to the object retrieved.</span><span style="color: #008000;">
</span><span style="color: #008080;">08</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> (Prevent other client committing changes</span><span style="color: #008000;">
</span><span style="color: #008080;">09</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> at the time between object retrieval and version</span><span style="color: #008000;">
</span><span style="color: #008080;">10</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> retrieval )</span><span style="color: #008000;">
</span><span style="color: #008080;">11</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #0000FF;">If</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Not</span><span style="color: #000000;"> _container.Ext.SetSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> _container.Ext.GetID(pilot).ToString(), </span><span style="color: #800080;">3000</span><span style="color: #000000;">) </span><span style="color: #0000FF;">Then</span><span style="color: #000000;">
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                        Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error. The object is locked</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                        </span><span style="color: #0000FF;">Continue</span><span style="color: #000000;"> </span><span style="color: #0000FF;">While</span><span style="color: #000000;">
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">If</span><span style="color: #000000;">
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> objVersion </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Long</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Ext.GetObjectInfo(pilot).GetVersion
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    _container.Ext.Refresh(pilot, Int32.MaxValue)
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    _container.Ext.ReleaseSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> _container.Ext.GetID(pilot).ToString())
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> save object version into _idVersions collection</span><span style="color: #008000;">
</span><span style="color: #008080;">19</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> This will be needed to make sure that the version</span><span style="color: #008000;">
</span><span style="color: #008080;">20</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> originally retrieved is the same in the database </span><span style="color: #008000;">
</span><span style="color: #008080;">21</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> at the time of modification</span><span style="color: #008000;">
</span><span style="color: #008080;">22</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> id </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Long</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Ext.GetID(pilot)
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    _idVersions.Add(id, objVersion)
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Updating pilot: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot.ToString() </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> version: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> objVersion.ToString())
</span><span style="color: #008080;">25</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    pilot.AddPoints(</span><span style="color: #800080;">1</span><span style="color: #000000;">)
</span><span style="color: #008080;">26</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    _updateSuccess </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">False</span><span style="color: #000000;">
</span><span style="color: #008080;">27</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    RandomWait()
</span><span style="color: #008080;">28</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">If</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Not</span><span style="color: #000000;"> _container.Ext.SetSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> _container.Ext.GetID(pilot).ToString(), </span><span style="color: #800080;">3000</span><span style="color: #000000;">) </span><span style="color: #0000FF;">Then</span><span style="color: #000000;">
</span><span style="color: #008080;">29</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                        Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error. The object is locked</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</span><span style="color: #008080;">30</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                        </span><span style="color: #0000FF;">Continue</span><span style="color: #000000;"> </span><span style="color: #0000FF;">While</span><span style="color: #000000;">
</span><span style="color: #008080;">31</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">If</span><span style="color: #000000;">
</span><span style="color: #008080;">32</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    _container.Set(pilot)
</span><span style="color: #008080;">33</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> The changes should be committed to be </span><span style="color: #008000;">
</span><span style="color: #008080;">34</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> visible to the other clients</span><span style="color: #008000;">
</span><span style="color: #008080;">35</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    _container.Commit()
</span><span style="color: #008080;">36</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    _container.Ext.ReleaseSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> _container.Ext.GetID(pilot).ToString())
</span><span style="color: #008080;">37</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">If</span><span style="color: #000000;"> _updateSuccess </span><span style="color: #0000FF;">Then</span><span style="color: #000000;">
</span><span style="color: #008080;">38</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                        Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Updated pilot: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot.ToString())
</span><span style="color: #008080;">39</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">If</span><span style="color: #000000;">
</span><span style="color: #008080;">40</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    Console.WriteLine()
</span><span style="color: #008080;">41</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> The object version is not valid after commit</span><span style="color: #008000;">
</span><span style="color: #008080;">42</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> - should be removed</span><span style="color: #008000;">
</span><span style="color: #008080;">43</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    _idVersions.Remove(id)
</span><span style="color: #008080;">44</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">While</span><span style="color: #000000;">
</span><span style="color: #008080;">45</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Finally</span><span style="color: #000000;">
</span><span style="color: #008080;">46</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                _container.Close()
</span><span style="color: #008080;">47</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">48</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div></span><p>A semaphore is used for locking the object
before saving and the lock is released after commit when the changes become
visible to the other clients. The semaphore is assigned a name based on object
ID to make sure that only the modified object will be locked and the other
clients can work with the other objects of the same class simultaneously.</p>

<p>Locking the object for the update only
ensures that no changes will be made to the object from the other clients
during update. However the object might be already changed since the time when
the current thread retrieved it. In order to check this we will need to
implement an event handler for the updating event:</p>

<span name="cs_wiki_filter" csw_filters="cs"><div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">OptimisticThread.cs: <span class="fscMemberName">RegisterCallbacks</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> RegisterCallbacks()
</span><span style="color: #008080;">2</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RegisterCallbacks_1867_69_40_293_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            IEventRegistry registry </span><span style="color: #000000;">=</span><span style="color: #000000;"> EventRegistryFactory.ForObjectContainer(_container);
</span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #008000;">//</span><span style="color: #008000;"> register an event handler to check collisions on update</span><span style="color: #008000;">
</span><span style="color: #008080;">5</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            registry.Updating </span><span style="color: #000000;">+=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> CancellableObjectEventHandler(OnUpdating);
</span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        }</span></span></div></pre></div></div><div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">OptimisticThread.cs: <span class="fscMemberName">OnUpdating</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> OnUpdating(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> sender, CancellableObjectEventArgs args)
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_80_934_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            Object obj </span><span style="color: #000000;">=</span><span style="color: #000000;"> args.Object;
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #008000;">//</span><span style="color: #008000;"> retrieve the object version from the database</span><span style="color: #008000;">
</span><span style="color: #008080;">05</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            </span><span style="color: #0000FF;">long</span><span style="color: #000000;"> currentVersion </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Ext().GetObjectInfo(obj).GetVersion();
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">long</span><span style="color: #000000;"> id </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Ext().GetID(obj);
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #008000;">//</span><span style="color: #008000;"> get the version saved at the object retrieval</span><span style="color: #008000;">
</span><span style="color: #008080;">08</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            IEnumerator i </span><span style="color: #000000;">=</span><span style="color: #000000;"> _idVersions.GetEnumerator();
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">long</span><span style="color: #000000;"> initialVersion </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #0000FF;">long</span><span style="color: #000000;">)_idVersions[id];
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (initialVersion </span><span style="color: #000000;">!=</span><span style="color: #000000;"> currentVersion)
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_554_840_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Collision: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Stored object: version: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> currentVersion);
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">New object: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> obj </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> version: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> initialVersion);
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                args.Cancel();
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>            }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">else</span><span style="color: #000000;">
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_OnUpdating_1936_58_870_924_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">20</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                _updateSuccess </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>            }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">22</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        }</span></span></div></pre></div></div> <br></p></span><span name="cs_wiki_filter" csw_filters="vb">
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">OptimisticThread.vb: <span class="fscMemberName">RegisterCallbacks</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub RegisterCallbacks()</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RegisterCallbacks_2057_69_8_277_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> RegisterCallbacks()
</span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> registry </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IEventRegistry </span><span style="color: #000000;">=</span><span style="color: #000000;"> EventRegistryFactory.ForObjectContainer(_container)
</span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #008000;">'</span><span style="color: #008000;"> register an event handler to check collisions on update</span><span style="color: #008000;">
</span><span style="color: #008080;">4</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            </span><span style="color: #0000FF;">AddHandler</span><span style="color: #000000;"> registry.Updating, </span><span style="color: #0000FF;">AddressOf</span><span style="color: #000000;"> OnUpdating
</span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div>
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">OptimisticThread.vb: <span class="fscMemberName">OnUpdating</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub OnUpdating()</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_OnUpdating_2128_58_8_972_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> OnUpdating(</span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> sender </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Object</span><span style="color: #000000;">, </span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> args </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> CancellableObjectEventArgs)
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> obj </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Object</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> args.Object
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #008000;">'</span><span style="color: #008000;"> retrieve the object version from the database</span><span style="color: #008000;">
</span><span style="color: #008080;">04</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> currentVersion </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Long</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Ext.GetObjectInfo(obj).GetVersion
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> id </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Long</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Ext.GetID(obj)
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #008000;">'</span><span style="color: #008000;"> get the version saved at the object retrieval</span><span style="color: #008000;">
</span><span style="color: #008080;">07</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> i </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IEnumerator </span><span style="color: #000000;">=</span><span style="color: #000000;"> _idVersions.GetEnumerator
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> initialVersion </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Long</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(_idVersions(id), </span><span style="color: #0000FF;">Long</span><span style="color: #000000;">)
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">If</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Not</span><span style="color: #000000;"> (initialVersion </span><span style="color: #000000;">=</span><span style="color: #000000;"> currentVersion) </span><span style="color: #0000FF;">Then</span><span style="color: #000000;">
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Collision: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Stored object: version: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> currentVersion.ToString())
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">New object: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> obj.ToString() </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> version: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> initialVersion.ToString())
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                args.Cancel()
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Else</span><span style="color: #000000;">
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                _updateSuccess </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">True</span><span style="color: #000000;">
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">If</span><span style="color: #000000;">
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div> <br>
</p>
</span><p>In the above case the changes are discarded
and a message is sent to the user if the object is already modified from
another thread. You can replace it with your own strategy of collision
handling.</p>

<p>Note: the supplied example has random delays
to make the collision happen. You can experiment with the delay values to see
different behavior.</p>
<span name="cs_wiki_filter" csw_filters="cs">

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">OptimisticThread.cs: <span class="fscMemberName">RandomWait</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> RandomWait()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_34_296_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">try</span><span style="color: #000000;">
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_64_175_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Random r </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Random();
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Thread.Sleep((</span><span style="color: #0000FF;">int</span><span style="color: #000000;">)(</span><span style="color: #800080;">5000</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;"> r.Next(</span><span style="color: #800080;">1</span><span style="color: #000000;">)));
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>            }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">catch</span><span style="color: #000000;"> (Exception e)
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsOptimisticThread.Cs_OptimisticThread.Cs_RandomWait_2619_62_220_286_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Interrupted!</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>            }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        }</span></span></div></pre></div></div>

</span>

<span name="cs_wiki_filter" csw_filters="vb">


<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">OptimisticThread.vb: <span class="fscMemberName">RandomWait</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub RandomWait()</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsOptimisticThread.Vb_OptimisticThread.Vb_RandomWait_2747_62_8_304_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> RandomWait()
</span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> r </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Random </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Random
</span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> sleepTime </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Integer</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">5000</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;"> r.Next(</span><span style="color: #800080;">1</span><span style="color: #000000;">)
</span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Thread.Sleep(sleepTime)
</span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Catch</span><span style="color: #000000;"> e </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Exception
</span><span style="color: #008080;">7</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Interrupted!</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</span><span style="color: #008080;">8</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">9</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div>


</span>


<p><br>
</p>
</div>
    </div>
    <div id="footer">
					This revision (1) was last Modified 2006-12-18T14:39:30 by Tetyana.
				</div>
  </body>
</html>