Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda