To work with asynchronous programming, do I need an asynchronous connection?

0

Good morning friends I am seeing some tutorials on the management of asynchronous programming with .net, in windows form .. many show concepts and basic practices on how to implement it.

But my doubts is. when we want to work with persistence of data, either with Databases. Would I have to make an asynchronous connection?

I'm looking at the documentation with a micro orm called dapper. and reviewing some of their methods, some have implemented that part by default.

for example. This is the way to work synchronously

var result = VariablesGlobales.GlobalConnection.Query("SELECT * FROM ...").firstOrDefault();

It turns out that there is another similar function but adding Async in their method to differentiate them.

var result = await VariablesGlobales.GlobalConnection.QueryAsync("SELECT * FROM ...");

My connection could be said to be a global statement of this. in a static class.

public static class VariablesGlobales
    {
        private static System.Data.SqlClient.SqlConnection _GlobalConnection;
        public static String UsuarioNombre { get; set; }
        public static String EmpresaNombre { get; set; }
        public static String SucursalNombre { get; set; }
        public static int UsuarioID { get; set; }
        public static int EmpresaID { get; set; }
        public static int SucursalID { get; set; }
        public static int RolID { get; set; }
        public static string Rol { get; set; }
        // TIEMPO DE EJECUCION DE LA APLICACION, Y BLOQUEO EN TIEMPO DE INACTIVIDAD

        public static int Horas { get; set; }

        public static int Minutos { get; set; }


        public static System.Data.SqlClient.SqlConnection GlobalConnection
        {
            get
            {
                _GlobalConnection = _GlobalConnection ?? new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
                return _GlobalConnection;
            }

            set
            {
                _GlobalConnection = value;
            }
        }
    }

Now working with the ExecuteAsync .. and performing the basic operations in a Database.

Is an asynchronous connection necessary? If so, how can you implement it?

Thank you.

    
asked by JuanL 17.10.2018 в 17:16
source

1 answer

2

In winform you would benefit from the asincrono job if you do not want to block the UI thread for example showing a progress bar or some icon that reflects that the app is working If you do it in sincrona the thread of the UI is blocked and the app seems frozen, this is where the Thread class or the BackgroundWorker is used, but if you can apply async/await it is much better.

Generally, applying this technique is observed in web development, since it requires solving several request requests that are not blocked.

    
answered by 17.10.2018 / 17:24
source