<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: lock code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 28 Aug 2008 12:55:35 GMT</pubDate>
    <description>DZone Snippets: lock code</description>
    <item>
      <title>File lock</title>
      <link>http://snippets.dzone.com/posts/show/4017</link>
      <description>Lock files so that no one else can access it:&lt;br /&gt;&lt;code&gt;&lt;br /&gt; string filename = "c:\\sample.htm";&lt;br /&gt; FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, &lt;br /&gt; FileShare.None); //locks file&lt;br /&gt;&lt;br /&gt; ...&lt;br /&gt;&lt;br /&gt; stream.Close(); //unlocks file&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;or&lt;br /&gt;&lt;code&gt;&lt;br /&gt; string filename = "c:\\sample.htm";&lt;br /&gt; FileStream stream = File.Open(filename, FileMode.Open);&lt;br /&gt; stream.Lock(0, stream.Length); //locks file&lt;br /&gt;&lt;br /&gt; ...&lt;br /&gt;&lt;br /&gt; stream.Unlock(0, stream.Length); //unlocks file&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Mon, 14 May 2007 22:29:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4017</guid>
      <author>mstampar (Miroslav Stampar)</author>
    </item>
    <item>
      <title>Open another app as content handler</title>
      <link>http://snippets.dzone.com/posts/show/131</link>
      <description>Current python for series 60 (version 1) doesn't support graphics drawing on screen. But it still allows you to open an image file or other content file using external content handler. Here is the short and shorter versions to demonstrate.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# this version wait for external app to exit, then it continue.&lt;br /&gt;import e32&lt;br /&gt;lock = e32.Ao_lock()&lt;br /&gt;handler = appuifw.Content_handler(lock.signal)&lt;br /&gt;hander.open(filename)  # eg. an image file&lt;br /&gt;lock.wait()	# wait for lock.signal to unlock&lt;br /&gt;&lt;br /&gt;# this is a short, one-line version which doesn't wait&lt;br /&gt;appuifw.Content_handler().open(filename)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 11 Apr 2005 04:44:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/131</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
