Pausing all tasks when condition is met
reading cancellationtokensource. i'm ok cancelling tasks if need i'm not sure how use it.
assistance appreciated.
here code:
private static object lockobject = new object();
public semaphore sema { get; set; }
public overdraftdata getoverdraftitem()
{
lock (lockobject)
{
return this.overdraftcollection.dequeue();
}
}
public void domywork()
{
this.sema= new semaphore(25,25);
queue<overdraft> data = new queue<overdraft>();
(decimal = 0; < 40000; i++)
{
data.enqueue(new overdraft { account = i, limit = });
}
list<task> tasks = new list<task>();
do
{
this.sema.waitone();
overdraftdata od= this.getoverdraftitem();
tasks.add(task.factory.startnew(() => { makecall(od); }));
}
while (data.count > 0);
task.waitall(tasks.toarray());
this.sema.dispose();
}
public servicereponse makecall(overdraft od)
{
try
{
servicereponse response= this.modifylimits(od);
if( response.successful==false)
{
this.insertfailurereason(response.message);
}
}
finally
{
this.sema.release();
}
}
public serviceresponse modifylimits(overdraft od)
{
servicereponse response= servicecall1();
if( response.successful==false)
return response;
response= servicecall2();
if( response.successful==false)
return response;
return servicecall3();
}
i'm no on multi-threading, but:
this worrysome, if vendor **thinks** issue due something, and pause tasks **a few seconds** when something.
1st, **think** guess, expect rework **think** when previous **think** doesn't stand
2nd, **a few seconds**, define ~~few~~.
2 seconds? 10 seconds?
3rd, , i'm not sure u doing **cancelling** equivalent pause.
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment