0

l have OraConn.ExecuteNonQuery(sql) which is calling oracle procedure now l want to run it in background by using threading

So, how i can do this in my code below

public void Row_Inserted(OrderedDictionary rsold, OrderedDictionary rsnew) {

                //ew_Write("Row Inserted");
                //ghalib

                 string theMONTH = rsnew["MONTH"].ToString();
                            string theYEAR = rsnew["YEAR"].ToString();
                            if (theMONTH.Length < 2)
                            {
                                theMONTH = 0 + theMONTH;
                            }
                            int ReadingDate = Convert.ToInt32(theYEAR + theMONTH);
                            int myReadingType = Convert.ToInt32(rsnew["READING_TYPE"].ToString());
                            if (myReadingType == 1)
                            {
                                var OraConn = ew_GetConn();


                                string sql = "CALL READING_DATA(" + ReadingDate + ")";
                                OraConn.ExecuteNonQuery(sql);


                                }
                            else if (myReadingType == 2)
                            {
                                var OraConn = ew_GetConn();

                                string sql = "CALL GetData()";
                                OraConn.ExecuteNonQuery(sql);
                            }
            }
ghalib
  • 203
  • 1
  • 2
  • 9
  • If you just want it asynchronous try this: `Task.Factory.StartNew(() => OraConn.ExecuteNonQuery(sql));` – Sebastian Siemens Aug 25 '16 at 05:44
  • I don't know what API you are using. But you may have an `ExecuteNonQueryAsync` method, so look into that. Otherwise, `Task.Run` is your way to run a method on the ThreadPool. If you expect it to be long running, you might need to specify that using `TaskCreationOptions.LongRunning` – Zein Makki Aug 25 '16 at 05:45
  • dear my question is not duplicated !! – ghalib Aug 25 '16 at 05:49
  • @ghalib You have a function that you need to run in the background, there are tons of answers for that on StackOverflow. One of them is in the link provided. `Task task = Task.Run((Action) Row_Inserted); await task;` you need to look at the `async/await` combination and follow that: https://msdn.microsoft.com/en-us/library/mt674882.aspx – Zein Makki Aug 25 '16 at 05:54

0 Answers0