我正在尝试创建一个调用库中线程的Windows服务。这一切都在c#中。该库具有从oracle数据库读取,处理数据,将其存储在SQL Server数据库中并更新oracle数据库中的记录的函数。我对此运行测试,看到循环运行大约80,000次,然后没有抛出任何错误(我甚至检查了事件日志)没有任何反应。请帮忙 这是代码
Windows服务
protected override void OnStart(string[] args)
{
try
{
base.OnStart(args);
controller = new BillingController();
thread = new Thread(new ThreadStart(controller.dowork));
thread.Start();
AppLogs.LogtoFile("SmartCDRBillingService.log", string.Format("SmartCDRBillingService started successfully"));
}
catch (Exception ex)
{
AppLogs.LogtoFile("SmartCDRBillingService.log", string.Format("Start Service error: {0}: {1}:", ex.Message.ToString(), ex.InnerException));
}
}
控制器
public BillingController()
{
AppConfig.LoadSettings();
}
public void dowork()
{
try
{
BillingQueue nLogic = new BillingQueue();
nLogic.QueueWorkItems();
}
catch (Exception ex)
{
//log
AppLogs.LogtoFile("BillingController.log", string.Format("dowork error: {0}: {1}:", ex.Message.ToString(), ex.InnerException));
}
}
队列
public void QueueWorkItems()
{
new System.Threading.Thread(new System.Threading.ThreadStart(doQueueWork)).Start();
}
private void doQueueWork()
{
counter = 1;
while (true)
{
counter++;
List<EventUsageObject> eList = new List<EventUsageObject>();
try
{
eList = _osqlcon.getallusageevents();
if (eList.Count == 0)
{
continue;
}
else
{
ProcessUsageRequest(eList);//for Event Usage
}
}
catch (Exception ex)
{
//log the error
AppLogs.LogtoFile("BillingQueue.log", string.Format("doQueueWork error: {0}: {1}:", ex.Message.ToString(), ex.InnerException));
}
}
}
public List<EventUsageObject> getallusageevents()
{
List<EventUsageObject> recobjec = new List<EventUsageObject>();
OracleConnection conn = new OracleConnection();
try
{
conn.ConnectionString = osql.getOracleConnectionString();
conn.Open();
OracleCommand command = conn.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
string query = "SMART_DWH_OBJECT.GETALLEVENTSUSAGE";
command.CommandText = query;
OracleParameter myParameter = new OracleParameter("rc", OracleDbType.RefCursor);
command.Parameters.Add("OUT_DATA", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
using (OracleDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
{
reader.FetchSize = 10000;
while (reader.Read())
{
try
{
EventUsageObject info = new EventUsageObject();
info.CallStart = Convert.ToDateTime(reader["E_TIME"].ToString());
info.CallingMsisdn = reader["ACC_NBR"].ToString();
info.CalledMsisdn = reader["CALLED_MSISDN"].ToString();
info.Re_Id = Convert.ToInt32(reader["RE_ID"].ToString());
info.EventName = reader["EVENT_NAME"].ToString();
info.Duration = Convert.ToInt32(reader["DURATION"].ToString());
info.Duration2 = Convert.ToInt32(reader["DURATION2"].ToString());
info.Duration3 = Convert.ToInt32(reader["DURATION3"].ToString());
info.Duration4 = Convert.ToInt32(reader["DURATION4"].ToString());
info.Uplink = Convert.ToInt32(reader["UPLINK"].ToString());
info.Downlink = Convert.ToInt32(reader["DOWNLINK"].ToString());
info.PriceList = reader["PRICE_LIST"].ToString();
info.Cell_A = reader["CELL_A"].ToString();
info.Cell_B = reader["CELL_B"].ToString();
info.Acct_item_Type_Id1 = Convert.ToInt32(reader["ACCT_ITEM_TYPE_ID1"].ToString());
info.Acct_item_Type_Id2 = Convert.ToInt32(reader["ACCT_ITEM_TYPE_ID2"].ToString());
info.Acct_item_Type_Id3 = Convert.ToInt32(reader["ACCT_ITEM_TYPE_ID3"].ToString());
info.Acct_item_Type_Id4 = Convert.ToInt32(reader["ACCT_ITEM_TYPE_ID4"].ToString());
info.BalanceType1 = reader["BALANCE_TYPE1"].ToString();
info.BalanceType2 = reader["BALANCE_TYPE2"].ToString();
info.BalanceType3 = reader["BALANCE_TYPE3"].ToString();
info.BalanceType4 = reader["BALANCE_TYPE4"].ToString();
string d1 = reader["CHARGE1"].ToString();
string d2 = reader["CHARGE2"].ToString();
string d3 = reader["CHARGE3"].ToString();
string d4 = reader["CHARGE4"].ToString();
info.Charge1 = Convert.ToInt32(reader["CHARGE1"].ToString());
info.Charge2 = Convert.ToInt32(reader["CHARGE2"].ToString());
info.Charge3 = Convert.ToInt32(reader["CHARGE3"].ToString());
info.Charge4 = Convert.ToInt32(reader["CHARGE4"].ToString());
info.Prebalance1 = Convert.ToDouble(reader["PRE_BALANCE1"].ToString());
info.Prebalance2 = Convert.ToDouble(reader["PRE_BALANCE2"].ToString());
info.Prebalance3 = Convert.ToDouble(reader["PRE_BALANCE3"].ToString());
info.Prebalance4 = Convert.ToDouble(reader["PRE_BALANCE4"].ToString());
info.Recstatus = 0;
recobjec.Add(info);
}
catch (Exception ex)
{
continue;
}
}
}
conn.Close();
conn.Dispose();
}
catch (Exception ex)
{
AppLogs.LogtoFile("DBAPIError.log", string.Format("DBAPI error on getallusageevents error: {0}: {1}:", ex.Message.ToString(), ex.StackTrace));
}
return recobjec;
}
public void ProcessUsageRequest(List<EventUsageObject> list)
{
try
{
//log the eventusage into the database.
if (list.Count == 0)
//do nothing
return;
else
_mssqlcon.logEventUsage(list, _osqlcon);
}
catch (Exception ex)
{
AppLogs.LogtoFile("BillingQueue.log", string.Format("ProcessUsageRequest error on loggingeventusage: {0}: {1}:", ex.Message.ToString(), ex.InnerException));
}
}
public void logEventUsage(List<EventUsageObject> ilist, DBAPI osql)
{
int counter = 0;
try
{
foreach (EventUsageObject log in ilist)
{
try
{
counter++;
sql.executeNonQueryStoredProcedure("dbo.sp_dwh_eventusage", log.CallStart.ToString(), log.CallingMsisdn, log.CalledMsisdn, log.Re_Id.ToString(),
log.EventName.ToString(), log.Duration.ToString(), log.Duration2.ToString(), log.Duration3.ToString(),
log.Duration4.ToString(), log.Uplink.ToString(), log.Downlink.ToString(), log.PriceList, log.Cell_A,
log.Cell_B, log.Acct_item_Type_Id1.ToString(), log.Acct_item_Type_Id2.ToString(), log.Acct_item_Type_Id3.ToString(),
log.Acct_item_Type_Id4.ToString(), log.BalanceType1, log.Charge1.ToString(), log.BalanceType2, log.Charge2.ToString(),
log.BalanceType3, log.Charge3.ToString(), log.BalanceType4, log.Charge4.ToString(), log.Recstatus.ToString(), log.Prebalance1.ToString(),
log.Prebalance2.ToString(), log.Prebalance3.ToString(), log.Prebalance4.ToString());
string query = "UPDATE dwh_ug_eventusage SET recstatus = 1" +
" WHERE E_TIME = TO_DATE('" + log.CallStart + "', 'MM/DD/YYYY HH:MI:SS PM') AND ACC_NBR = '" + log.CallingMsisdn + "'";
osql.executeNonQueryText(query);
AppLogs.LogtoFile("BillingQueue.log",
string.Format("ProcesssubscriptionRequest has processed: {0} record",
log.Msisdn));
}
catch (SqlException ex)
{
if (ex.Number == 2601)
{
string query = "UPDATE dwh_ug_eventusage SET recstatus = 1" +
" WHERE E_TIME = TO_DATE('" + log.CallStart + "', 'MM/DD/YYYY HH:MI:SS PM') AND ACC_NBR = '" + log.CallingMsisdn + "'";
osql.executeNonQueryText(query);
}
AppLogs.LogtoFile("DBAPIError.log", string.Format("DBAPI error on logEventUsage: {0}: {1}:",
continue;
}
}
}
catch (Exception ex)
{
AppLogs.LogtoFile("DBAPIError.log", string.Format("DBAPI error on logEventUsage: {0}: {1}:",
ex.Message.ToString(), ex.StackTrace));
}
}