I want to convert List<Object>
to List<U>
where as U
is the type that can be generated Dynamically but List is not accepting U
in C#
Waiting for a value to be true, requires thread?
I have written a small method. It basically calls to a service (not web service) to set a lock attribute. It does work, but I am interested in improving it. Should I really be running this in a new thread?
I have this running inside a do..while
and I have no thread.sleep
between calls.
I am using the stopwatch to record when its actually more than 20 seconds and I exit anyway as no lock was able to be set.
public bool ObtainLock(Uri lockUri)
{
bool lockResult = false;
var sw = new Stopwatch();
sw.Start();
do
{
lockResult = myService.SetLockBit(lockUri);
}
while (!lockResult || sw.ElapsedMilliseconds >= 20000);
sw.Stop();
return lockResult;
}
It just seems to me it could be improved, and the threading worries me. A note, the myservice isn't a web service, its just another method on a class so I can use Task<..>
here.
And the stopwatch I am using, is that an acceptable way of implementing a timeout?