Program hanging

  • Thread starter Thread starter Cat
  • Start date Start date
C

Cat

Hi there

I have written a C# program which writes lots of info to a text file. When
it's doing this, however, the entire program seems to hang - if you click on
the UI all of its controls disappear and it appears as a white box. It's
still writing to the file though because after about five minutes the UI
goes back to normal and the text file is complete. I've tried popping up a
form displaying a status bar but this doesn't help at all. Basically I'd
like for the UI to stay pretty while the text file is being written,
although I don't want to allow the user to do anything while the writing is
taking place. Any ideas?

Cat
 
Hi Cat,

You should do the file writing asynchronously using a separate thread for the purpose or a stream's asynchronous methods (typically named using Begin and End, as in BeginRead, BeginWrite). A separate thread would let you implement a progress bar too.
 
If you're having a progress bar and updating it, do be careful. Updating
controls from other threads can get real messy if you dont do it the
right way
 
Back
Top