加载数据时异步和等待 [英] Async and Await When Loading Data
问题描述
button1.KeyDown + = async(o,n)=>
{//这是一个搜索功能,用户会输入
//文本框,然后在每个按键中,应用程序将连接
//到数据库并搜索是否找到了已键入的数据
//然后将其绑定到gridcontrol
var getData = Task.Run(()=> ; Call_To_Database_NotAsync);
var result = await getData;
gridcontrol.Datasource = result;
}
当用户快速键入并且与数据库的连接速度很慢时,网格控件是否可能根本不包含任何数据?
问候
< blockquote>
我认为如果
Call_To_Database_NotAsync 或服务器端函数不支持多个并行执行,因此可以观察到不良影响。找到一种方法来取消过时的请求。
button1.KeyDown+=async(o,n)=> {
//This is a search function, the user will type something on
// a textbox then in every keypress, the application will connect
//to the database and search if the typed data has been found
//then bind it to a gridcontrol
var getData=Task.Run(()=> Call_To_Database_NotAsync); var result=await getData; gridcontrol.Datasource=result; }
Is there a possibility that the grid control will contain no data at all when the user types fast and the connection to the database is slow?
Regards
I think that if Call_To_Database_NotAsync or server-side functions are not designed to support multiple parallel executions, then it is possible to observe undesirable effects. Find a way to cancel the requests that are obsolete.
这篇关于加载数据时异步和等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!