S
S
sergeevpetro2016-05-17 17:08:29
NoSQL
sergeevpetro, 2016-05-17 17:08:29

Why does the program freeze?

Good afternoon!
Please help me figure it out. By pressing the button in Mongo, an element should be added to the document field ... The button goes out, but does not become available back and the whole form hangs, although the element was added to the database (checked through the Mongo console). What am I doing wrong?

private async Task AddReplic(string mess, string str)
        {
            var client1 = new MongoClient(connectionString);
            var database1 = client1.GetDatabase("test");
            var collection1 = database1.GetCollection<BsonDocument>("testcollection");
            var filter = Builders<BsonDocument>.Filter.Eq("Mess", mess);
            var update = Builders<BsonDocument>.Update.AddToSet("Replics",str);
            var result = await collection1.UpdateOneAsync(filter, update);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            button2.Enabled = false;
            AddReplic("ТекстТекст","УраУра").GetAwaiter().GetResult();
            button2.Enabled = true;
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#algooptimize #bottize, 2016-05-18
@sergeevpetro

Add async to the click method definition and await when the method is called. From a mobile phone it’s hard to see what’s in add, the dependency can still be if there is a block before the first await

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question