开发者

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 applicatio开发者_开发技巧n, 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜