asdfasfd
asdfasfd

Reputation: 291

Show a progress bar while a function runs in a loop until it returns a value

I have a function that runs an sql query for data that may or may not be there. Since I need to run this function continually until it returns the proper value how can I run a progress bar until the loop finishes.

status = Logic.ProcessResource(currentInstance)
While status.woID.Count <= 0
     status = Logic.ProcessResource(currentInstance)
End While

How can I run this and show another form with a progress bar until the loop exits?

Upvotes: 1

Views: 1032

Answers (1)

Idle_Mind
Idle_Mind

Reputation: 39122

My comments as an answer...

Put that code into a different thread, then use a ProgressBar in "Marquee" mode to indicate an operation that is ongoing, but has no known ending time.

Yes...but you still need to put the query/loop in a different thread...otherwise the main UI thread will to be to busy to animate and remain responsive to the user.

Look at the BackgroundWorker control, or using a Task, with Async/Await.

You'd show the form, start the worker, wait for worker to finish, then close the form. The BackgroundWorker() has UI friendly events like RunWorkerCompleted that are already marshaled to the UI thread for you.

Upvotes: 1

Related Questions