|
TheGreatAndPowerfulOz wrote: don't be a sunshine. Why don't you put your comment where the sun don't shine.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Well, elephant that why don't you?
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
John Simmons / outlaw programmer wrote:
this.DoAgentWork();
do
{
this.DoAgentWork();
if (!taskObj.CancelToken.IsCancellationRequested)
{
this.DoAgentWork();
}
} while (!taskObj.CancelToken.IsCancellationRequested); Is, IMHO, better. Removed <snip>'d code for clarity.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
Actually, this would be even better:
this.DoAgentWork(taskObj.CancelToken);
(and I already made a not in my code to do that).
That way a long-running process inside DoAgentWork could watch the status of the token.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
This bit looks wrong to me:
Task waiter = new Task(() =>
{
SpinWait.SpinUntil( () => tokenSource.IsCancellationRequested || taskObj.CancelToken.IsCancellationRequested);
}, tokenSource.Token);
waiter.Start();
waiter.Wait();
You're starting a task on a background thread which blocks until either the AgentTask is cancelled or the target time is reached, but then you're blocking the current thread waiting for that task to complete.
I suspect there's a better way of doing it - but this isn't the right forum to discuss it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The waiter has a cancellation token and waits until either the timeout or a cancelation token is activated. Beyond that, the thread needs to wait until the waiter is done before continuing, and it doesn't block any other running agent tasks. I don't understand how that's incorrect.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
You're pushing work off onto a background thread, and then blocking the current thread waiting for the work to finish. You could almost certainly move the work out onto the current thread without changing the behaviour:
Task waiter = new Task(() =>
{
SpinWait.SpinUntil( () => tokenSource.IsCancellationRequested || taskObj.CancelToken.IsCancellationRequested);
}, tokenSource.Token);
waiter.Start();
waiter.Wait();
SpinWait.SpinUntil( () => tokenSource.IsCancellationRequested || taskObj.CancelToken.IsCancellationRequested);
There might be a way to make it work without blocking the current thread, using async / await .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
But I WANT to block the thread (and it's even still responsiove to the cancel token). It's simply waiting for a time span to go by before doing the work at the bottom of the loop.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Yes, you want to block the current thread; but your code is blocking TWO threads!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Good point.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
Doing it your way makes it run forever. I still need it to cancel itself after the timeout has expired.
I think I see what you're saying - gotta run it that way to see what it does.
Real work is yanking on my sleeve, so I have to pick this up in an hour or two.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
John Simmons / outlaw programmer wrote: Sql Express Agent
Get a couple certificates and now you are an expert!
Mongo: Mongo only pawn... in game of life.
|
|
|
|
|
|
Add "Undo Pending Changes" to the code window tab's context menu.
Now I won't have to search all over the solution to find the file because I accidentally hit the keyboard.
If it's not broken, fix it until it is
|
|
|
|
|
In 2012 + there's a button at the top of the solution explorer with two arrows:
->
<-
That will highlight the current open document in solution explorer. Use it many times a day myself.
|
|
|
|
|
|
I know. I really meant is as a bitch
If it's not broken, fix it until it is
|
|
|
|
|
|
ctrl-z
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
Mine's "Just work".
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Kevin Marois wrote: Now I won't have to search all over the solution to find the file because I accidentally hit the keyboard.
Right click the Code --> Source Control --> Undo Pending Changes
|
|
|
|
|
Here[^]
If it's not broken, fix it until it is
|
|
|
|
|
Meme generator, here i come.
|
|
|
|
|
I wonder why they Photoshopped the "other" weasel out of your picture?
Original untouched image[^]
Contrary to popular belief, nobody owes you anything.
|
|
|
|