后台工作者/Thread.Sleep 搜索
我有一个用于搜索的BackgroundWorker。可以执行两种不同的搜索,一种针对 SQL DB,另一种针对 Accpac DB。为了适应 Accpac DB 的缓慢执行时间,我使用 Thread.Sleep。问题是,当我在 SQL DB 上进行搜索时,我给出的参数表明它应该只返回活动记录。如果我移动 Thread.Sleep 以适应我的 Accpac 搜索,那么我的 SQL 结果将返回所有记录,而不是仅返回活动记录。如果我移动 Thread.Sleep 以适应 SQL 搜索,则返回的 Accpac 搜索结果会出现问题。
除了 Thread.Sleep 之外还有其他选择吗?
I have a BackgroundWorker that I use on a Search. Two different Searches can be done, one to a SQL DB and another to an Accpac DB. To accommodate for slow execution time to the Accpac DB, I use Thread.Sleep. The problem is, when I do a search on my SQL DB, I give parameters stating it should only return active records. If I move the Thread.Sleep to accommodate for my Accpac search, then my SQL results return all records instead of Active only. If I move Thread.Sleep to accommodate for my SQL search, then there are issues on the Accpac search results returned.
Are there any other alternatives other than Thread.Sleep?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您应该研究一下线程同步类,例如 WaitHandles。 ManualResetEvent 可能非常适合您。
http://www.yoda.arachsys.com/csharp/threads/waithandles.shtml
Sounds like you should look into Thread Synchronization classes such as WaitHandles. A ManualResetEvent would probably work pretty well for you.
http://www.yoda.arachsys.com/csharp/threads/waithandles.shtml