I assume you're executing this time consuming operation on the UI thread.
Have a look at the
BackgroundWorker[
^] class.
Delegate the work to a background thread and show the user some notification that work is being done at the moment.
This way the application won't hang.