<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Is PersistenceManager thread-safe?</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce Classic : Is PersistenceManager thread-safe?</description>
  <pubDate>Thu, 11 Jun 2026 09:18:25 -700</pubDate>
  <lastBuildDate>Tue, 29 Jan 2008 06:04:54 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=666</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Is PersistenceManager thread-safe? : Seem to work Thank you </title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2473#2473</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=152" rel="nofollow">f3rland</a><br /><strong>Subject:</strong> 666<br /><strong>Posted:</strong> 29-Jan-2008 at 6:04am<br /><br />Seem to work<DIV></DIV>Thank you <img src="http://www.ideablade.com/forum/smileys/smiley4.gif" height="17" width="17" border="0" align="absmiddle" alt="Big%20smile" />]]>
   </description>
   <pubDate>Tue, 29 Jan 2008 06:04:54 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2473#2473</guid>
  </item> 
  <item>
   <title>Is PersistenceManager thread-safe? : f3rland, take a look at the Sy...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2465#2465</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 666<br /><strong>Posted:</strong> 26-Jan-2008 at 7:17pm<br /><br />f3rland, take a look at the System.Threading.SynchronizationContext class.&nbsp; You should be able to use it to Post or Send arguments back to your main thread.&nbsp; Something like this:<DIV>&nbsp;</DIV><DIV>&nbsp;&nbsp;&nbsp; // "Main" thread</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Create PM, etc.</DIV><DIV><FONT size=2>&nbsp;&nbsp; _synchronizationContext = System.Threading.</FONT><FONT color=#008080 size=2>SynchronizationContext</FONT><FONT size=2>.Current;</FONT></DIV><DIV><FONT size=2></FONT>&nbsp;</DIV><DIV><FONT size=2></FONT>&nbsp;</DIV><DIV><FONT size=2>&nbsp;&nbsp; private void SomeEventHandler(SomeType someParam ...) {</FONT></DIV><DIV><FONT size=2><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object</FONT><FONT size=2> &#091;&#093; newArgs = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>object</FONT><FONT size=2>&#091;&#093; {&nbsp;&nbsp;someParam ...&nbsp;};</FONT></FONT></DIV><DIV><FONT size=2><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp;&nbsp; </FONT></FONT><FONT size=2><FONT size=2>_synchronizationContext.Post(ThreadSafeHandler, newArgs);</FONT></FONT></DIV><DIV><FONT size=2><FONT size=2>&nbsp;&nbsp; }</FONT></FONT></DIV><DIV><FONT size=2><FONT size=2></FONT></FONT>&nbsp;</DIV><DIV><FONT size=2><FONT size=2>&nbsp; private void ThreadSafeHandler(args) {</FONT></FONT></DIV><DIV><FONT size=2>&nbsp;&nbsp;&nbsp; // can now safely use PM</FONT></DIV><DIV><FONT size=2><FONT size=2>&nbsp; }</DIV><DIV></FONT>&nbsp;&nbsp;&nbsp; </FONT></DIV><DIV><FONT size=2>&nbsp;</DIV></FONT>]]>
   </description>
   <pubDate>Sat, 26 Jan 2008 19:17:48 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2465#2465</guid>
  </item> 
  <item>
   <title>Is PersistenceManager thread-safe? : Events that came from our componentare...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2464#2464</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=152" rel="nofollow">f3rland</a><br /><strong>Subject:</strong> 666<br /><strong>Posted:</strong> 26-Jan-2008 at 11:49am<br /><br />Events that came from our component&nbsp;are raised&nbsp;from a thread. <DIV>So another ExecutionContext...</DIV><DIV>&nbsp;</DIV><DIV>Simplified example : </DIV><DIV>&nbsp;</DIV><DIV>Class MainApplication</DIV><DIV>&nbsp;&nbsp; Private mComponent as new SomeComponent</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;&nbsp; Private Sub SomeEvent(byval SomeParam as SomeType) Handles mComponent.SomeEvent</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Here we are in another context (thread)&nbsp;so we dont have access to main Persistence Manager.</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'We can see Shared PersistenceManager, modify it and access it but that raise exception as shown in first post.</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'And that's here we need to refresh PersistenceManager data.</DIV><DIV>&nbsp;&nbsp; End Sub</DIV><DIV>End Class</DIV><span style="font-size:10px"><br /><br />Edited by f3rland - 26-Jan-2008 at 12:09pm</span>]]>
   </description>
   <pubDate>Sat, 26 Jan 2008 11:49:24 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2464#2464</guid>
  </item> 
  <item>
   <title>Is PersistenceManager thread-safe? : Why can&amp;#039;t you have your main...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2463#2463</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=23" rel="nofollow">davidklitzke</a><br /><strong>Subject:</strong> 666<br /><strong>Posted:</strong> 26-Jan-2008 at 11:38am<br /><br />Why can't you have your main thread process these events?<DIV>&nbsp;</DIV><DIV>It is also OK if you have a separate Persistence Manger collect these inserted, modified, and deleted entities in its own cache, then have your main Persistence Manager import these entities.</DIV><span style="font-size:10px"><br /><br />Edited by davidklitzke - 26-Jan-2008 at 11:39am</span>]]>
   </description>
   <pubDate>Sat, 26 Jan 2008 11:38:58 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2463#2463</guid>
  </item> 
  <item>
   <title>Is PersistenceManager thread-safe? : We don&amp;#039;t have many choices. One...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2462#2462</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=152" rel="nofollow">f3rland</a><br /><strong>Subject:</strong> 666<br /><strong>Posted:</strong> 26-Jan-2008 at 11:13am<br /><br />We don't have many choices.<DIV>One of our component sends us events through threads.</DIV><DIV>Those events tell us to refresh data for some tables.</DIV><DIV>And from that event we need to refresh entities in the persistence manager of the application (main thread).</DIV><DIV>&nbsp;</DIV><DIV>I know we can work with lock and/or Mutex.</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Sat, 26 Jan 2008 11:13:25 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2462#2462</guid>
  </item> 
  <item>
   <title>Is PersistenceManager thread-safe? : The answer to your question is...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2461#2461</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=23" rel="nofollow">davidklitzke</a><br /><strong>Subject:</strong> 666<br /><strong>Posted:</strong> 26-Jan-2008 at 10:18am<br /><br />The answer to your question is "No, the PersistenceManager is not thread-safe".<DIV>&nbsp;</DIV><DIV><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Please read this advice from our documentation:<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3></FONT></o:p></P><FONT face="Times New Roman"><FONT size=3></P><DIV>The .NET Framework Class Library documentation for the DataSet class says this about its thread-safety: </FONT><SPAN style="FONT-SIZE: 8pt">This type is safe for multithreaded read operations. You must synchronize any write operations. </SPAN><FONT size=3>The same is true for the DevForce PersistenceManager. To make it thread-safe for write operations would require that we make thread-safe every method therein – and every method of the business objects it manages, including property setters. This would increase the PersistenceManager</FONT></FONT><FONT size=3><SPAN style="FONT-FAMILY: 'Lucida Sans Unicode'">&#8223;</SPAN><FONT face="Times New Roman">s complexity – and degrade its performance – significantly. Every user of the PersistenceManager, and every use thereof, would incur the performance penalty, whether such users and uses required thread-safety or not. At least 90% of the use cases that people submit to us for multi-threading involve retrieving data while other operations proceed. For this we have provided Asynchronous Queries. You call the PersistenceManager</FONT><SPAN style="FONT-FAMILY: 'Lucida Sans Unicode'">&#8223;</SPAN><FONT face="Times New Roman">s GetEntitiesAsync() method, and we take care of putting the data retrieval operation on a separate thread so that the rest of your application can continue processing. Any number of such asynchronous queries can be launched simultaneously. You can read about asynchronous queries in the DevForce Developers Guide (in the chapter on Object Persistence), and see sample code in the Asynchronous Queries instructional unit that is shipped with the product. Does this mean that you can</FONT><SPAN style="FONT-FAMILY: 'Lucida Sans Unicode'">&#8223;</SPAN><FONT face="Times New Roman">t do multi-threading (other than by using Asynchronous Queries) in a DevForce application? No, it does not. It just means that <I>you should never share a single PersistenceManager, or any of the entities it manages in its cache</I>, across multiple threads. Let us repeat: <o:p></o:p></FONT></FONT></DIV><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="FONT-FAMILY: 'Courier New'">o </SPAN><FONT face="Times New Roman">Never share a PersistenceManager across more than one thread. <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="FONT-FAMILY: 'Courier New'">o </SPAN><FONT face="Times New Roman">Never share entities from a given PersistenceManager in more than one thread. <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Note that the problems that occur with multi-threaded applications are, by their very nature, timing-dependent and difficult to diagnose, reproduce, and test for. Your multi-threaded process can work successfully for long periods of time, then fail catastrophically when two or more inconsistent changes happen to be made simultaneously. You should definitely not count on this failure occurring at a convenient time!<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><SPAN style="FONT-SIZE: 6.5pt">4 </SPAN><FONT size=3>Excerpted from </FONT></FONT><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">”</SPAN><FONT size=3><FONT face="Times New Roman">Characterizing Thread Safety” by Brian Goetz, available on the web at: <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Arial">http://www-128.ibm.com/developerworks/java/library/j-jtp09263.html <o:p></o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">If your multi-threaded aspirations involve DevForce business objects: <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Use a different PersistenceManager in each thread. Such PersistenceManagers can do anything a normal PersistenceManager can do; they can fetch (both synchronously and asynchronously), save, and so forth. <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Never use PersistenceManager.DefaultManager when multi-threading – the DefaultManager is “global” to the AppDomain and will be shared among any threads in which it is used. <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Never communicate entities across thread boundaries. If the caller must know about some entities, send a list of PrimaryKeys across the thread boundary in a call back. Alternatively, you could bury EntitySets in a call back to serialize copies of entities across the thread boundary. <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 9pt"><o:p><FONT face="Times New Roman">&nbsp;</FONT></o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman"><B>If You’re Determined To Do Multi-Threading… </B>Be sure you really need multiple threads. Remember, if all you want to do is fetch data asynchronously, you will be fully satisfied with Asynchronous Queries. Don</FONT><SPAN style="FONT-FAMILY: 'Lucida Sans Unicode'">&#8223;</SPAN><FONT face="Times New Roman">t mess around with multi-threading if this is all you want to do. </FONT></FONT><SPAN style="FONT-SIZE: 11.5pt; FONT-FAMILY: 'Franklin Gothic Medium'">IdeaBlade DevForce Developers Guide Object Persistence </SPAN><FONT face="Times New Roman"><SPAN style="FONT-SIZE: 8pt">IdeaBlade DevForce Q&amp;A.doc Copyright © 2006, IdeaBlade, Inc, all rights reserved </SPAN><FONT size=3>56 <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Use caution when writing <I>any </I>multi-threaded app. Don't be lulled into a false sense of confidence just because it is easy to spawn a BackgroundWorker in .NET 2.0. Multi-threading is still hard. The BackgroundWorker made the syntax easy: it did not make good multi-threaded design easier! If you</FONT><SPAN style="FONT-FAMILY: 'Lucida Sans Unicode'">&#8223;</SPAN><FONT face="Times New Roman">re new to multi-threaded programming, work with someone who has significant prior experience doing it, if at all possible. If you can</FONT><SPAN style="FONT-FAMILY: 'Lucida Sans Unicode'">&#8223;</SPAN><FONT face="Times New Roman">t arrange that, do some serious reading and study on the topic before attempting it on a critical application. If your multi-threaded aspirations involve DevForce business objects:<SPAN style="COLOR: navy; FONT-FAMILY: Arial"><o:p></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-FAMILY: Arial"><o:p><FONT size=3>&nbsp;</FONT></o:p></SPAN></P></DIV>]]>
   </description>
   <pubDate>Sat, 26 Jan 2008 10:18:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2461#2461</guid>
  </item> 
  <item>
   <title>Is PersistenceManager thread-safe? : We tried to remove entities from...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2460#2460</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=152" rel="nofollow">f3rland</a><br /><strong>Subject:</strong> 666<br /><strong>Posted:</strong> 25-Jan-2008 at 7:04pm<br /><br />We tried to remove entities from persistence manager in an event wich come from a thread and&nbsp;we get that error :<DIV><a href="http://www.ideablade.com/forum/uploads/20080125_220048_error.txt" target="_blank">uploads/20080125_220048_error.txt</A></DIV><DIV>&nbsp;</DIV><DIV>The error is not raised directly when&nbsp;our code is executed and seem to be from .NET Framework.</DIV><DIV>&nbsp;</DIV><DIV>Here is&nbsp;the code in the event handler&nbsp;:</DIV>If IdeaBlade.Persistence.PersistenceManager.DefaultManager.DataSet.Tables.Contains("Model:SomeObject") Then<BR>&nbsp; IdeaBlade.Persistence.PersistenceManager.DefaultManager.RemoveEntities(GetType(Model.SomeObject), DataRowState.Unchanged)<BR>End If<DIV>&nbsp;</DIV><DIV>We cannot use the "Me.Invoke" in that context because the object is not a control.</DIV><DIV>&nbsp;</DIV><DIV>Maybe there is another way to achieve the same task without that hack?</DIV><DIV><U><strong>All we want to do is removing obsolete entities from cache to refetch them.</strong></U></DIV><DIV><strong><U></U></strong>&nbsp;</DIV><DIV>Or there is a way to&nbsp;force refresh&nbsp;for some objects base on filter or EntityQuery?</DIV><DIV>&nbsp;</DIV><DIV>Thanks for your help!</DIV>]]>
   </description>
   <pubDate>Fri, 25 Jan 2008 19:04:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=666&amp;PID=2460#2460</guid>
  </item> 
 </channel>
</rss>