Back to ".Net en Gesluite Lêers..."

This is a viewer only at the moment see the article on how this works.

To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk

This is a preview from the server running through my markdig pipeline

.NET C# Imported mostlylucidcouk

.Net en Gesluite Lêers...

Friday, 20 February 2004

OK, kan iemand uitleggen waarom ik het niet uitdrukkelijk kan checken of ik een lêer kan sluiten voordat ik eruit lees (iM SK3e., check dat niemand anders de lêer sluit voordat hij eruit probeert te lezen FileSystemWatcher om te wachten tot files in een gids worden gecreëerd voordat je een taak activeert - goed, maar er lijkt geen makkelijke manier te zijn om te controleren of een lêer is 'leesbaar' voordat je begint te lezen. FileStream en de fout die het gooit als de lêer door een ander proces gesluit wordt.

        private static int m_ReadAttempts = 0;
        private string  ReadFileFromDisk(string filePath)
        {
            try
            {
                if(!File.Exists(filePath))
                {
                    MessageBox.Show("Sorry, but the file specified " + Environment.NewLine + filePath + Environment.NewLine + "Cannot be found");
                    return string.Empty;
                }
            using(FileStream fs = new FileStream(filePath,FileMode.Open,FileAccess.Read,FileShare.Read))
                {
                        using(StreamReader sr = new StreamReader(fs)) 
                        {
                            string tmpStr = sr.ReadToEnd();
                            sr.Close();
                            m_ReadAttempts =0;
                            return tmpStr;
                        }
                
                }        
            }
            catch(IOException ex)
            {
                    if(m_ReadAttempts < 10)
                {
                    Thread.Sleep(500);
                    m_ReadAttempts++;
                    return ReadFileFromDisk(filePath);
                }
                else
                {
                    throw ex;
                }
            }
        }
logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.