Form waiting for a request

3

Problem

My form makes a requisição determine a database (select, insert, update, delete values), however whenever these requests are made a crash occurs on the form (a freeze)! How do I prevent forms from receiving these crashes regardless of request?

Note: The longer the request takes, the longer the lockout. An example is a select * from tabela; that captures a large amount of values in the database. I've had both issues in JAVA and C #.

  

Warning: When I say request I am referring to the connection and search in the database.

    
asked by anonymous 25.02.2014 / 19:47

3 answers

5

If your problem is to query a large amount of data, no matter the language, a forward query will always hang while waiting for the database to return.

The best alternative is to perform an asynchronous query, that is, the process (thread) that makes the query does not need to be blocked waiting for the response of the database, in this case, there would be a callback method to receive the response from the database when it is finished being consulted.

Following is a link explaining how to do this type of simplest way query in C #:

In version 5.0 of C # the magic words async and await that resolve the callback have been included. Here is a link explaining this usage:

25.02.2014 / 21:38
2

Some points could be taken into account for optimization:

  • Is your table correctly indexed? If you make a query using LIKE and the table is large, without index, performance will be impaired.
  • Are you looking for ID? At the time of a delete or update, is the key the ID of the table? This can also influence.
  • When searching for data do not select * from, but do not discriminate each attribute select fieldA, fieldB from.
  • If the table has many data the correct one is to make a page query. Search the information bit by bit.
  • In the case of a CRUD, pagination is not recommended because the user expects an immediate response to his action. The user usually wants immediate feedback for a CRUD action - usually something very simple.

If your table is too large (millions of records) you could use techniques to decrease the size of the table:

  • Break the table (PeopleABameName, PeopleNameFet, ...)
  • Partitioning by features of the database itself (several banks already have this functionality)
  • Reducing the number of indexed columns
26.02.2014 / 02:49
0

Basically you should use threads, or use asynchronous methods in .NET 4.5.

Read more about threads, and async.

link

    
25.02.2014 / 19:54