mattgcon
mattgcon

Reputation: 4858

C# check for new application items when app is running

I have a Reporting system that has a list of reports available for running to the user. What I want to be able to do is periodically have the application look for new reports on the SQL server and repopulate the list of reports available.

But I want to do this without locking the application, I want this to be seamless and not have the user even know it is happening.

How can I do this the most efficient way possible?

Thank you

Upvotes: 2

Views: 247

Answers (2)

John Arlen
John Arlen

Reputation: 6698

If I understand your question, you are looking to have a background thread perform this work, without affecting the user, and update the GUI when done.

Look into BackgroundWorker helper class.

Upvotes: 2

Mark Byers
Mark Byers

Reputation: 839054

I'd suggest using a background thread to do the polling. You can start a new Thread object and poll the server, sleeping after each check. If you find a change you can fetch the data and then you will need to call Invoke to update the GUI because this cannot be done on a different thread.

An alternative is to use a timer and do the check inside the Tick event, but if the check takes a long time (and it can take a long time if your server is busy or if there is a table lock) then it will block your application so I'd advise against this approach.

Upvotes: 2

Related Questions