daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Jan 12th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use c# threadpool or task to call a function and get return value
  2. cmd = new OleDbCommand { Connection = con, CommandText = "Select recid,col_A,col_B from tblData"};
  3. dr = cmd.ExecuteReader();
  4.  
  5. if (dr.HasRows)
  6. {
  7.    cmdRec = new OleDbCommand { Connection = con };
  8.    while (dr.Read())
  9.     {
  10.     sReqResult = DoProcessing(dr["col_A"].ToString(), dr["col_B"].ToString(), dr["PARAM2"].ToString());
  11.         sSql = "update tblData set STATUS='" + sReqResult + "' where recid = '" + dr["recid"] + "'";
  12.     cmdRec.CommandText = sSql;
  13.     cmdRec.ExecuteNonQuery();
  14.     }
  15. }
  16. dr.close();
  17.    
  18. while(true)
  19.         {
  20.             string enabled = null;
  21.             currentInstance = OrderManager.getCurrentInstance();
  22.             SqlCommand command = new SqlCommand("Select OrderNumber, BatchStatus from dbo.Orders where StatusChanged='1'", connection1);
  23.             SqlDataReader reader = command.ExecuteReader();
  24.             if (reader.HasRows)
  25.             {
  26.                 while (reader.Read())
  27.                 {
  28.                     Int64 orderNum = (Int64)reader[0];
  29.                     int index = linqForOrderIndex(orderNum);
  30.                     string batchStatus = (string)reader["BatchStatus"];
  31.                     SqlCommand statusChangedFalse = new SqlCommand("Update dbo.orders Set StatusChanged = '0' where OrderNumber = '" + orderNum + "'", connection2);
  32.                     switch (batchStatus)
  33.                     {
  34.                         case "Untouched":
  35.                             currentInstance.Orders[index].batchStatus = "Untouched";
  36.                             break;
  37.                         case "Batch Ready":
  38.                             currentInstance.Orders[index].batchStatus = "Batch Ready";
  39.                             break;
  40.                         case "Shipped":
  41.                             currentInstance.Orders[index].batchStatus = "Shipped";
  42.                             break;
  43.                         case "Error":
  44.                             currentInstance.Orders[index].batchStatus = "Error";
  45.                             break;
  46.                     }
  47.                     statusChangedFalse.ExecuteNonQuery();
  48.  
  49.                     Thread.Sleep(1000);
  50.  
  51.                     reader.Close();
  52.                     reader = command.ExecuteReader();
  53.                 }
  54.  
  55.                 currentInstance.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
  56.                     new Action(
  57.                         delegate()
  58.                         {
  59.                             currentInstance.refreshTreeFilters();
  60.                             currentInstance.refreshOrderCounts();
  61.                             currentInstance.batchReadyView();
  62.                         }
  63.                     ));  
  64.             }
  65.       }
  66.    
  67. if (dr.HasRows)
  68. {
  69.     object someDataToWorkWith = "data";
  70.  
  71.     Action<object> resultCallback = (theResults) =>
  72.     {
  73.         // Executed once the workItem is finished.
  74.         // Work with and/or present the results here.
  75.     };
  76.  
  77.     WaitCallback workItem = (dataOrSomeDetails) =>
  78.     {
  79.         // This is the main async-part. Work with or fetch data here.
  80.         // You can also access any variables from the containing method.
  81.         // When finished working, execute callback:
  82.         resultCallback("someResults");
  83.     };
  84.  
  85.     ThreadPool.QueueUserWorkItem(workItem, someDataToWorkWith);
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top