Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
How to make an existing code block async in .net?

I have an existing code block with Linq to SQL queries and HTTP requests, that I'd like to make async for the purpose of using less threads.

Will it suffice to put the code block in an async method, like so?

    public async Task<Customer> ProcessACustomer()
    {
        return await GetCustomer();
    }

    public Task<Customer> GetCustomer()
    {
        // Linq to SQL query here

        // HTTP request here

        Customer customer;
        return Task.FromResult<Customer>(customer);
    }

...or do I have to make every piece of logic in GetCustomer() async to accomplish this?

My hurdle here is that I have a ton of logic in that method (oversimplified above), so time will be an issue. Also, I can't seem to convert my Linq To SQL queries to async, as the async extension methods are not available for some reason (System.Data.Linq.Table does not contain a definition for FirstOrDefaultAsync() f.ex.).

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Will it suffice to put the code block in an async method, like so?

No. The GetCustomer method is not asynchronous. It synchronously performs its work and then returns a completed task. This will not save any threads.

do I have to make every piece of logic in GetCustomer() async to accomplish this?

If you want to convert to async, then you should start at the opposite end. Don't start with the goal of making ProcessACustomer (or GetCustomer) asynchronous. Instead, start with the lowest-level API. Whatever your db access method is, make that asynchronous first and then let the async grow out from there.

My hurdle here is that I have a ton of logic in that method (oversimplified above), so time will be an issue.

This is a classic tradeoff. It may be worthwhile to convert to async, or it may be worthwhile to buy a few more servers instead.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda