Click here to Skip to main content
15,905,136 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with Drag-Drop operation with Picture Box.Pls Help Pin
JoeSharp7-Jun-07 20:15
JoeSharp7-Jun-07 20:15 
GeneralRe: Problem with Drag-Drop operation with Picture Box.Pls Help Pin
Chintan.Desai7-Jun-07 21:19
Chintan.Desai7-Jun-07 21:19 
QuestionEditing a Textbox and CheckBox in Excel file using Interop Pin
TheMajorRager7-Jun-07 17:51
TheMajorRager7-Jun-07 17:51 
AnswerRe: Editing a Textbox and CheckBox in Excel file using Interop Pin
Ray2Boston13-Jul-10 11:37
Ray2Boston13-Jul-10 11:37 
Questionhow can I get the next item? Pin
lockepeak7-Jun-07 16:45
lockepeak7-Jun-07 16:45 
AnswerRe: how can I get the next item? Pin
Christian Graus7-Jun-07 17:44
protectorChristian Graus7-Jun-07 17:44 
QuestionTableLayoutPanel repaint issue. Pin
Zerox MXI7-Jun-07 16:42
Zerox MXI7-Jun-07 16:42 
AnswerRe: TableLayoutPanel repaint issue. Pin
Salogus7-Jun-07 16:52
Salogus7-Jun-07 16:52 
GeneralRe: TableLayoutPanel repaint issue. Pin
Zerox MXI7-Jun-07 16:59
Zerox MXI7-Jun-07 16:59 
QuestionIs software installed on pc? Pin
Adeel Chaudhry7-Jun-07 13:21
Adeel Chaudhry7-Jun-07 13:21 
AnswerRe: Is software installed on pc? Pin
Mark Greenwood7-Jun-07 14:56
Mark Greenwood7-Jun-07 14:56 
AnswerRe: Is software installed on pc? Pin
Niiiissssshhhhhuuuuu7-Jun-07 18:37
Niiiissssshhhhhuuuuu7-Jun-07 18:37 
QuestionLimiting DB access to only through application Pin
tempmail17-Jun-07 11:33
tempmail17-Jun-07 11:33 
AnswerRe: Limiting DB access to only through application Pin
Christian Graus7-Jun-07 11:47
protectorChristian Graus7-Jun-07 11:47 
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 

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.