The form freezes because your code is running on the UI/Main thread.
So because you are Sleeping the thread while notepad is not open then your form will lock up.
If you run your code asynchronously then you move the worker thread away from the UI.
See here for an C# async overview