Click here to Skip to main content
15,887,342 members
Home / Discussions / C#
   

C#

 
AnswerRe: Limiting DB access to only through application Pin
Russell Jones7-Jun-07 22:38
Russell Jones7-Jun-07 22:38 
QuestionHierarchical Distributed Genetic Algorithm for Image Segmentation Pin
Petra7-Jun-07 10:46
Petra7-Jun-07 10:46 
AnswerRe: Hierarchical Distributed Genetic Algorithm for Image Segmentation Pin
Dave Kreskowiak7-Jun-07 13:28
mveDave Kreskowiak7-Jun-07 13:28 
AnswerRe: Hierarchical Distributed Genetic Algorithm for Image Segmentation Pin
Christian Graus7-Jun-07 15:35
protectorChristian Graus7-Jun-07 15:35 
QuestionFileSystemWatcher Pin
LCI7-Jun-07 10:28
LCI7-Jun-07 10:28 
AnswerRe: FileSystemWatcher Pin
Ylno7-Jun-07 11:42
Ylno7-Jun-07 11:42 
GeneralRe: FileSystemWatcher Pin
LCI8-Jun-07 9:36
LCI8-Jun-07 9:36 
AnswerRe: FileSystemWatcher Pin
mav.northwind8-Jun-07 22:33
mav.northwind8-Jun-07 22:33 
Why are you performing such a strange busy wait? That's completely useless IMO.
If you really have to wait you should at least use Thread.Sleep so that your application doesn't burn CPU cycles needlessly.

In order to find out if a file has been written completely, I'm using a mechanism that's working reliably so far (written from memory, so no guarantees):
public void WaitForFileCompletion(string path, int maxwait)
{
  int wait = 0;
  while (true)
  {
    try
    {
      FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
      fs.Close(); // no exception was thrown so close the stream
      fs.Dispose();
      return; // and return - now the file is complete
    }
    catch (IOException)
    {
      wait += 100;
      Thread.Sleep(100); // wait 100ms for completion
      if (wait > maxwait)
        throw new ApplicationException("Timeout reached waiting for completion of file.");
    }
  }
}

The idea is to open the file exclusively. If another application is still busy writing to the file, this will fail. As soon as opening the file succeeds you can be sure it's been written completely.

Regards,
mav

--
Black holes are the places where God divided by 0...

QuestionSearch for non-ASCII characters in a text file Pin
Koshv7-Jun-07 10:22
Koshv7-Jun-07 10:22 
AnswerRe: Search for non-ASCII characters in a text file Pin
Guffa7-Jun-07 13:12
Guffa7-Jun-07 13:12 
Questionbrainbench test with no answer? Pin
brsecu7-Jun-07 10:14
brsecu7-Jun-07 10:14 
AnswerRe: brainbench test with no answer? Pin
Luc Pattyn7-Jun-07 12:45
sitebuilderLuc Pattyn7-Jun-07 12:45 
AnswerRe: brainbench test with no answer? Pin
Vrungar6-Apr-11 9:04
Vrungar6-Apr-11 9:04 
AnswerRe: brainbench test with no answer? Pin
Luc Pattyn6-Apr-11 13:46
sitebuilderLuc Pattyn6-Apr-11 13:46 
QuestionGraphics image convert to GraphicsPath ? Pin
Epsilone37-Jun-07 9:59
Epsilone37-Jun-07 9:59 
AnswerRe: Graphics image convert to GraphicsPath ? Pin
Dave Kreskowiak7-Jun-07 10:39
mveDave Kreskowiak7-Jun-07 10:39 
GeneralRe: Graphics image convert to GraphicsPath ? Pin
Epsilone37-Jun-07 12:14
Epsilone37-Jun-07 12:14 
GeneralRe: Graphics image convert to GraphicsPath ? Pin
Dave Kreskowiak7-Jun-07 13:25
mveDave Kreskowiak7-Jun-07 13:25 
AnswerRe: Graphics image convert to GraphicsPath ? Pin
Christian Graus7-Jun-07 12:09
protectorChristian Graus7-Jun-07 12:09 
GeneralRe: Graphics image convert to GraphicsPath ? Pin
Epsilone37-Jun-07 12:24
Epsilone37-Jun-07 12:24 
GeneralRe: Graphics image convert to GraphicsPath ? Pin
Christian Graus7-Jun-07 15:42
protectorChristian Graus7-Jun-07 15:42 
QuestionHow can I resize the DataGridView back to defult size? Pin
Khoramdin7-Jun-07 9:39
Khoramdin7-Jun-07 9:39 
AnswerRe: How can I resize the DataGridView back to defult size? Pin
Dave Kreskowiak7-Jun-07 10:38
mveDave Kreskowiak7-Jun-07 10:38 
Questionoracle Client Pin
shereem khaleel7-Jun-07 9:34
shereem khaleel7-Jun-07 9:34 
AnswerRe: oracle Client Pin
Rick van Woudenberg7-Jun-07 11:42
Rick van Woudenberg7-Jun-07 11:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.