سؤال

I have what would appear to be a simple problem but I am not sure how to solve it.

What I want to do is perform a lengthy operation that is called from the UI thread on a worker thread so that the UI remains responsive - however this still has to be sequential, I want to wait for the action to complete but still pump the message queue so the UI doesn't get the dreaded (Not Responding...) error.

How is it possible in an elegant fashion, the ugly and diabolical way would be to spawn a thread and enter a DoEvents loop until its done.

هل كانت مفيدة؟

المحلول

What you are asking for is contradictory. You want the UI to execute (be responsive) but you don't want it to execute your code (wait for the action do complete).

You could either show a modal visual element that prevents the user from interacting with your main interface or you can disable all the visual elements (and navigation if relevent) whilst your background task completes.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top