Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use c# threadpool or task to call a function and get return value
- cmd = new OleDbCommand { Connection = con, CommandText = "Select recid,col_A,col_B from tblData"};
- dr = cmd.ExecuteReader();
- if (dr.HasRows)
- {
- cmdRec = new OleDbCommand { Connection = con };
- while (dr.Read())
- {
- sReqResult = DoProcessing(dr["col_A"].ToString(), dr["col_B"].ToString(), dr["PARAM2"].ToString());
- sSql = "update tblData set STATUS='" + sReqResult + "' where recid = '" + dr["recid"] + "'";
- cmdRec.CommandText = sSql;
- cmdRec.ExecuteNonQuery();
- }
- }
- dr.close();
- while(true)
- {
- string enabled = null;
- currentInstance = OrderManager.getCurrentInstance();
- SqlCommand command = new SqlCommand("Select OrderNumber, BatchStatus from dbo.Orders where StatusChanged='1'", connection1);
- SqlDataReader reader = command.ExecuteReader();
- if (reader.HasRows)
- {
- while (reader.Read())
- {
- Int64 orderNum = (Int64)reader[0];
- int index = linqForOrderIndex(orderNum);
- string batchStatus = (string)reader["BatchStatus"];
- SqlCommand statusChangedFalse = new SqlCommand("Update dbo.orders Set StatusChanged = '0' where OrderNumber = '" + orderNum + "'", connection2);
- switch (batchStatus)
- {
- case "Untouched":
- currentInstance.Orders[index].batchStatus = "Untouched";
- break;
- case "Batch Ready":
- currentInstance.Orders[index].batchStatus = "Batch Ready";
- break;
- case "Shipped":
- currentInstance.Orders[index].batchStatus = "Shipped";
- break;
- case "Error":
- currentInstance.Orders[index].batchStatus = "Error";
- break;
- }
- statusChangedFalse.ExecuteNonQuery();
- Thread.Sleep(1000);
- reader.Close();
- reader = command.ExecuteReader();
- }
- currentInstance.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
- new Action(
- delegate()
- {
- currentInstance.refreshTreeFilters();
- currentInstance.refreshOrderCounts();
- currentInstance.batchReadyView();
- }
- ));
- }
- }
- if (dr.HasRows)
- {
- object someDataToWorkWith = "data";
- Action<object> resultCallback = (theResults) =>
- {
- // Executed once the workItem is finished.
- // Work with and/or present the results here.
- };
- WaitCallback workItem = (dataOrSomeDetails) =>
- {
- // This is the main async-part. Work with or fetch data here.
- // You can also access any variables from the containing method.
- // When finished working, execute callback:
- resultCallback("someResults");
- };
- ThreadPool.QueueUserWorkItem(workItem, someDataToWorkWith);
- }
Add Comment
Please, Sign In to add comment