我正在嘗試製作一個多線程程序,該程序從另一家公司所持有的服務器上獲取大量數據線程。目前一旦一個線程已經提取數據,它就會使用OdbcDataReader來讀取這些數據。但最終,我想要做的是將這些數據傳遞給另一個不同的線程,這將使用讀取器讀取和解析數據,以便當前線程可以繼續從數據庫中獲取更多數據。在不使用ODBC.DataReader的情況下將數據傳遞給另一個類C#
目前這裏是線程的代碼,直到讀者指向。
public class plexThread
{
OdbcConnection connection;
OdbcCommand command;
string sqlStatement;
OdbcDataReader reader;
string threadNumber;
DateTime startDate;
DateTime endDate;
public plexThread(string threadNumber)
{
connection = new OdbcConnection("XXXX");
this.threadNumber = threadNumber;
}
public void plexthread()
{
try
{
connection.Open();
startDate = ThreadInfo.useStartDate();
endDate = ThreadInfo.getEndDate();
DateTime timerStart = new DateTime();
DateTime now = DateTime.Now;
int timeout = 0;
bool dataCaptured;
while (startDate <= endDate)
{
dataCaptured = false;
DateTime startDatePlusDay = startDate.AddDays(+1);
Console.WriteLine("Thread" + threadNumber + " is picking up day: " + startDate);
string startDateString = startDate.ToString("yyyy-MM-dd");
string startDatePlusDayString = startDatePlusDay.ToString("yyyy-MM-dd");
sqlStatement = "call sprocXXXX(null, null, '" + startDateString + "', '" + startDatePlusDayString + "', null, null,null,null,'',null,null,null,null,null,null,'', 164407);";
command = new OdbcCommand(sqlStatement, connection);
while (dataCaptured == false)
{
if (timeout <= 5)
{
try
{
reader = command.ExecuteReader();
int fieldCount = reader.VisibleFieldCount;
while (reader.Read())
{
for (int i = 0; i < fieldCount; i++)
{
string data = reader[i].ToString();
}
不知道最好的辦法是什麼?