Jump to content
ewong

Determining why Delphi App Hangs

Recommended Posts

1 hour ago, aehimself said:

All was fine until only one code like this ran. In the moment two tried to connect simultaneously (not mentioning a couple of occasional deadlocks) connections took 5-10 times more than they normally would, if they connect by themselves. Also, UI was responsive, but sluggish.

Well, it's not the App.PM's fault, it's the misuse. You just run a continuous loop which could iterate millions times per second if there's no messages in the queue. Surely it eats up CPU time and other operations get slower. What happens if you uncomment that Sleep?

BTW, each additional connect you run adds one more nested loop with App.PM=>Button.OnClick=>Connect thus the call stack grows.

Edited by Fr0sT.Brutal

Share this post


Link to post
17 minutes ago, Fr0sT.Brutal said:

Well, it's not the App.PM's fault, it's the misuse. You just run a continuous loop which could iterate millions times per second if there's no messages in the queue. Surely it eats up CPU time and other operations get slower. What happens if you uncomment that Sleep?

BTW, each additional connect you run adds one more nested loop with App.PM=>Button.OnClick=>Connect thus the call stack grows.

I never said it was the fault of Application.ProcessMessages; it was mine for using it 🙂

 

Tbh I don't see a difference between running in a cycle of While thread.Terminated Do and dataset.Next millions of iterations. It just depends how much data you have.

 

Sleep was originally uncommented, I think I could go down to 5 ms sleep before starting to eat up the CPU.

 

But since I took a deep breath and started to get rid of this - I don't want to experiment to try to patch-the-patch to make it look better. This time I want to do it right 🙂

  • Like 1

Share this post


Link to post
2 hours ago, aehimself said:

But since I took a deep breath and started to get rid of this - I don't want to experiment to try to patch-the-patch to make it look better. This time I want to do it right 🙂

Doing things right is always a better option. But when it's too hard, only some ugly methods could help - but one has to understand what they're doing.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×