c# - Blocking Collection stops processing for some reason -


i have blocking collection of lists , process in task - add data blocking collection database. here part of code:

private static task _databasetask; private static readonly blockingcollection<list<someitem>> datatobeinsertedtodatabase = new blockingcollection<list<someitem>>(); public static void processinsertscollection() {     _databasetask = task.factory.startnew(() =>     {         foreach (list<someitem> data in datatobeinsertedtodatabase.getconsumingenumerable())         {             try             {                 datetime[] datetimes = data.select(d => d.contributiondatetime).toarray();                 string[] values = data.select(d => d.value).toarray();                 string[] someothervalues = data.select(d => d.someothervalues).toarray();                 program.incrementdatabaserecordsregistered(data.count);                 databaseclass.insertvalues(datetimes, values, someothervalues);             }             catch (exception ex)             {                 //log error             }         }     }); } 

function databaseclass:

public static bool insertvalues(datetime[] datetimes, string[] values, string[] someothervalues) {     if (!isconnected())     {         connect();     }     var rowsinserted = 0;     try     {         using (oraclecommand command = _connection.createcommand())         {             command.commandtext =                 string.format(                     "insert {0} (*****) values (:1, :2, :3)",                     _tablename);             command.parameters.add(new oracleparameter("1",                 oracledbtype.date,                 datetimes,                 parameterdirection.input));             command.parameters.add(new oracleparameter("2",                 oracledbtype.varchar2,                 values,                 parameterdirection.input));             command.parameters.add(new oracleparameter("3",                 oracledbtype.varchar2,                 someothervalues,                 parameterdirection.input));              command.arraybindcount = datetimes.length;             rowsinserted = command.executenonquery();         }     }     catch (exception ex)     {         //log error     }     return rowsinserted != 0; } 

the problem after few hours of application working data still being added blocking collection not processed. when debug not stop @ breakpoint inside task. when check variable _databasetask shows task running. _connection variable shows database connected. added try/catch foreach , in insertvalues function did not help. made static because firstly thought task collected gc. not.

probably problem connected calling database because in application have blocking collection , processing in task works without problems. not call there database function.

could please me find out why collection not consumed after few hours?

edit: please not vote down when not understand question. lower possibility knows solution sees question. did lot of research on problem.

today notice thread hangs on line rowsinserted = command.executenonquery(); try add timeout there , add transaction.

afer difficult investigation found issue. add answer, maybe someone.

the problem line rowsinserted = command.executenonquery(); default timeout oraclecommand 0 enforces no time limit. blocked other session hangs forever. solution add timeout command using commandtimeout property of oraclecommand. , implement mechanism of retrying insertion.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -