In order to avoid freezing of GUI, I wanted to run method connecting to DB asynchronously. Therefore I have written this:
DelegatLoginu dl = ConnectDB;
IAsyncResult ar = dl.BeginInvoke(null, null);
var result = (bool)dl.EndInvoke(ar);
But it is still freezing and I do not understand why. I thought BeginInvoke ensures the invoked code runs in another thread. Thank you!
Calling EndInvoke() will block until the BeginInvoke() call has completed.
You need this kind of pattern in order for your long-running method to invoke a callback when it finishes: