有什么办法可以在处理过程中取消DataAdapter.Fill命令? [英] Is there any way to cancel a DataAdapter.Fill command while it's processing?

查看:74
本文介绍了有什么办法可以在处理过程中取消DataAdapter.Fill命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我有一个执行对非常大的数据库的查询的表单.通常,查询需要大约4分钟的时间才能返回.为了确保在执行此查询时GUI的其余部分不会挂起,我将查询运行在单独的线程上.

Background: I have a form that executes a query to a very large database. Typically, the query takes ~4 minutes to return. To make sure that the rest of the GUI doesn't hang while this query is executing, I have the query running on a seperate thread.

目标:我希望能够在查询完成之前取消它.

Goal: I would like to be able to cancel the query before it has been completed.

问题:因为查询是在BackgroundWorker_DoWork事件处理程序中唯一运行的东西,所以我找不到在完成查询之前取消后台工作程序的任何方法.没有真正的切入点,因为DoWork事件只运行一次; 它不会循环.因此,我一直在寻找一种直接取消DataAdapter.Fill(DataSet,"TableName")命令的方法.反正我能做到吗?

Problem: Because the query is the only thing that runs in the BackgroundWorker_DoWork event handler, I can't find any way to cancel the background worker before it completes the query. There's no real entry point, becasuse the DoWork event only runs once; it doesn't loop. Thus, I've been looking for a way to directly cancel the DataAdapter.Fill(DataSet, "TableName") command. Is there anyway I can do this?

当用户尝试在查询完成之前关闭表单时,这已经引起了问题.即使我在FormClosing事件处理程序中调用了它的dispose方法,后台工作程序仍继续在后台处理.目前,唯一的解决方案 我发现正在延迟关闭窗体,直到查询完成.但是,这似乎很老套.不用等待4分钟让DataAdapter.Fill命令完成就可以关闭它吗?

This has been causing problems when the user tries to close the form before the query is complete. The background worker continues to process in the background even though I call its dispose method in the FormClosing event handler. At present, the only solution I've found is delaying the form close until the query is complete. This, however, seems very amature. Isn't there any way I can shut this down without waiting the 4 minutes for the DataAdapter.Fill command to complete?

推荐答案

从DataReader到DataAdapter.Fill.也许您可以使用它.
You can pass a DataReader to DataAdapter.Fill. Maybe you can work with that.


这篇关于有什么办法可以在处理过程中取消DataAdapter.Fill命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆