If this is a Windows Forms application, you might want to consider moving this into a threaded execution model. You can do this using either the BackgroundWorker
control, thread pooling with the ThreadPool
class, asynchronous methods Begin and End (such as Stream.BeginWrite
), or by manually handling the thread yourself (bit more complex).
A BackgroundWorker
will provide the easiest form of development by allowing you to handle events for the asynchronous code, and update a progress bar or label to show the current state of the execution. This will allow you to use Thread.Sleep
without the system warning the user that the application has hung.
Basically, in Windows Forms development you should be using some form of threading to handle long executions.