I have a system that is a Web Api, the control executes a class like this:
public class CrawlBO
{
public void IniciaProcesso()
{
...
CarregaConfiguracaoCrawlBO carregaconfiguracaocrawlbo = new CarregaConfiguracaoCrawlBO(type);
Task<ConfiguracaoCrawlModel> montarconfiguracao = carregaconfiguracaocrawlbo.MontarConfiguracaoAsync(type);
...
montarconfiguracao.Wait();
conf = montarconfiguracao.Result;
...
}
}
My class CarregaConfiguracaoCrawlBO
has a async
method, this is the class:
public class CarregaConfiguracaoCrawlBO
{
public async Task<ConfiguracaoCrawlModel> MontarConfiguracaoAsync(EnumOrigens type)
{
try
{
MYEntities db = new MYEntities ();
int t = (int)type;
CRAWL conf = await db.CRAWLs.Where(p => p.ID_ORIGEM == t).FirstOrDefaultAsync();
...
return c;
}
catch (Exception ex)
{
throw ex;
}
}
}
The problem is that it freezes on montarconfiguracao.Wait();
. I've done all test types, and I know that within Task
it freezes at the .FirstOrDefaultAsync();
line.
First I thought it might be some error, then I put try catch
, but it does not get error, then I thought it might be a problem in localhost
, but on the server it hangs in the same place too.
I would like to use .Wait()
because I can not put all methods as async
at one time.
Adding more content:
I know it for .Wait()
to wait for the task, but the problem that the task should take about 4 seconds, and it freezes even, an hour later and still there in the task without doing anything