How can a user cancel a long-running request?

Related: How can I cancel the SQL Server execution process programmatically

I created an application (Windows, WPF), which is basically a tool for viewing data in a database (Sql Server). The application does not have editing features.

The application provides the ability to search for records based on user input. For the most part, rows are scanned by a key column and run fairly quickly. But one column in the table is a large text field, and I want to provide the ability to search for rows based on the contents of this field. Because of this, the resulting sql query may take some time. I want to provide a Stop button so that the user can interrupt the search, if necessary. The link above uses the Kill command to kill the spid on the Sql server, but I'm not sure how this will work in my situation, since I use Entity Framework (4.1)

For example, suppose a query has a similar query:

var docs = from document in context.Documents join header in context.Headers on document.DocumentID equals header.HeaderID into headerGroup from subdoc in headerGroup.DefaultIfEmpty() where document.LargeTextColumn.Contains("search term") select (...) foreach (var item in docs) { //Do something with item here } 

Since the request does not actually occur until I repeat it with the foreach statement, how can I provide the user with a Stop Request button? It is like a stop button in Sql Server Management Studio.

Is it possible?

+6
source share
1 answer

This should help you: Cancel Entity Platform Request

+2
source

Source: https://habr.com/ru/post/888048/


All Articles