Form hangs during execution

Apr 23, 2015 at 9:02 PM
Hi everyone!

I have noticed that my C# Form hangs while the API is executed (Connection to a wrong IP or during a XboxFile.Copy, etc...)

Before.. using Process.. I was able to:
                while (!myProcess.HasExited)
                {
                    System.Threading.Thread.Sleep(250);
                    Application.DoEvents();
                }
to prevent the Forms from Hang...

Do you have any workaround please that would help avoiding the hang by any chance?

Thanks a lot for your help it is really appreciated :)

Cheers!
Developer
Apr 23, 2015 at 9:35 PM
It sounds like you need to re-design your application to run blocking calls like XboxFile.Copy asynchronously. Your user interface thread will then be able to continue interacting with the user (and display visual indicators of being busy like hourglass or progress bar).

The recommended way of introducing asynchronous logic into a new application is the Task-based Asynchronous Pattern (TAP).

See the general page for asynchronous programming here:
https://msdn.microsoft.com/en-us/library/hh156548(v=vs.110).aspx

See the page explaining TAP here:
https://msdn.microsoft.com/en-us/library/hh873175(v=vs.110).aspx

The last link also has code examples when you navigate further in the topic. Here they are for convenience:
https://msdn.microsoft.com/en-us/library/hh873177(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/hh873173(v=vs.110).aspx
Marked as answer by Perfo_Team_MTL on 4/24/2015 at 7:11 AM
Apr 24, 2015 at 3:12 PM
Awesome! Thanks a lot for your help!! It works very well with async "await Task.Run()" :)