c# - Windows Service not retrieving edited SQL rows -
i tried find answer using search, feel wording poorly decent results.
i have windows service uses linq-sql. should pull data table every 20 seconds, process data, update row accordingly , rinse , repeat.
sqldatacontext sqldb; protected override void onstart(string[] args) { servicelog1.writeentry("service1 started"); sqldb= new sqldatacontext (); //initalize , start timer service action timer timer = new timer(); timer.interval = 20000; // 20 seconds timer.elapsed += new elapsedeventhandler(this.dowork); timer.start(); } public void dowork(object sender, elapsedeventargs args) { list<items> items= sqldb.items.where(i=> i.processed == false).take(20).tolist(); if(items.count > 0) servicelog1.writeentry("processing " + items.count + " queue items."); //work work... //set items processed == true //submit changes db
my issue (and i'm not 100% sure issue) this:
if run through 3 unprocessed test items, update them processed should. simple test if scenario, if change value of processed 1 item false in sql, service create entry event log saying processing 1 item, item never updated again , processed on every loop.
this seems happen items edited in sql. new items processed normally. can explain me going on here?
as damien_the_unbeliever pointed out in question comments, issue related sqldatacontext keeping objects in memory. needed create new context each time timer elapses.
Comments
Post a Comment