The application actually doesn't get stuck in real, it is just the UI of your WPF that gets frozen when the processes to be executed a complex. In your code, this function can be simply just minimized, or put on to an asynchronous thread, which would execute apart from the UI thread.
Since you're a newbie to this async programming, I would like to forward you to MSDN to get a brief overview of the
async programming[
^]; writing an article to explain the concept of async programming in the QandA forums won't be a good idea.
Once you've created the async functions, each time a function that would be taking time executing can be put on a seperate async thread, where it will keep executing or working as a background thread. This way, you UI won't stop and the WPF application won't "freeze". This problem really is a major issue in WPF framework, because each and every programming; even me, has to go through this process. Because WPF has a single thread by default, which would not only perform the business logic but in turn is also responsible for the UI updates, such as Button state change and other UI related tasks. So, that is why when the thread is performing a function or executing a method, it doesn't perform anything for the UI, which causes a sense of "freezing" in the UI and it looks like the application got stuck, or the processing stopped! No, that is not a reason. Program (application) is running but there is another process that is taking time.
The major time consuming processes include, working with the HTTP resources, such as HTML documents or other files from the internet, other than these, the I/O resources like fetching data from Hard disk etc might consume some time. In these cases such problem occurs. It is better to perform such tasks asynchronously.
In your code, a System.IO code is also present and the arrays and other data processes are also time consuming, until they are executed the thread will be frozen.
Good luck! :-)