c# - How to execute asynchronously three separate queries in one method using ADO.NET ExecuteScalarAsync() -


So I'm trying to change my synchronous method to asnych set up - I have a method that checks Whether the user uses any company's products or not. I need different queries for each product, so I tried and decided to give a shot for asnych programming because I never waited for Task and , even if it is probably not the right position to do this but still I have changed my method to:

  Private static async Tasks & Lt; Bool & gt; IsUsingProducts (Intel Client ID) {bool isproduct = false; (Using SqlConnection connection1 = new SqlConnection (connString)) {SqlCommand firstProduct = new SqlCommand (firstQuery, connection1); First product. Comma timeout = 300; FirstProduct.Open (); Work NumberFaxed Product1 = First Product Exclsar sarsink (); // Input numberoffuesaid products = (int) firstproduct. Excl. SLAR (); // if (0 & lt; numberofsaid products) // {// isproduct = true; }}} (Using SQL Connection 2 = New SqlConnection (connString)) {SqlCommand secondProduct = new SqlCommand (secondQuery, connection2); SecondProduct.CommandTimeout = 300; Connection2.Open (); Job NumberOffsuded Products2 = Second Product EXPLORE SLASINC (); // Input Number Affected Products = (Int) Second Product Exclamation (); // if (0 & lt; numberofsaid products) // {// isproduct = true; //}} is the return product; }   

Actually this is a mix of the efforts made by me and has been left with whatever is synchronous from the previous method. In this case, I only care if the user is using any product or not, so I was checking the end of each query. Although sometimes I need actual counting, so at the end I want to be able to execute the questions in asnych mode and later it will have to prove how I will actually deal with the results.

Now it:

  Job numberoffice products2 = second product. EXECLUSION SLASACCNC ();   

I'm not giving any error, but I do not know how to proceed. I do not know how to do this how to add logic to check the result of each query (queries are a support, how do I know that there is already a result), and those results are in the actual type ("Code > Int )

execute SQLAsync back Work & lt; Object & gt; . You can use Cast Wait :

 Return with  Light First number on the first product (1) (first) wait for firstProduct.ExecuteScalarAsync () if (Products with numbers> gt; 0) {hasProduct = true;}   

The second It also goes for the method.

Now it:

  work numberofproductsproducts2 = second product.exlashSalarSink ();  < / Pre> 

I am not giving an error

This is because Tasks by Task , then you have a more consolidated basis You can use it as a square, but then you lose the result returned code t < / Html>

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -