c# - MongoDB CountAsync and Cursors not working in a Windows Service with the new driver -


i have windows service reads data sql server , write them on mongodb.

i'm trying adapt service new mongodb driver (using 2.0.1 version), i'm facing problems.

i have this:

 protected void onstart(string[] args)     {         threadexternalpage = new thread(new threadstart(facadefactory.getliveprice.updateexternalpage)); 

this code calls method.

 public async void updateexternalpage()     {         while (true)         {             mongoupdateproductbo mongo = new mongoupdateproductbo();             await mongo.updateexternalpage();         }     } 

now problem: everytime call line on mongo.updateexternalpage()

var count = await collection.countasync(new bsondocument()); 

the method exits without processing next instructions.

the same thing happens if execute line:

using (var cursor = await collection.find(filter).tocursorasync()) 

but if same thing using windows forms application, there's no problem! need code working in windows service. know if implementation wrong or if there's restriction using new mongodb driver?

i changed code following:

 var cursor = collection.find(filter).tocursorasync();         cursor.wait();          using (cursor.result)         {             while (cursor.result.movenextasync().result)             { 

and worked expected.

in same way, count works when change to:

        var temp = collection.countasync(new bsondocument());         temp.wait();         var count = temp.result; 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -