Click here to Skip to main content
15,905,508 members

Comments by eric881027 (Top 15 by date)

eric881027 27-Feb-15 22:10pm View    
Thanks for your informative answer!
But in the articles the cancel is called inside of the task, of course, the exception will be throw by the task thread, and if you call the cancel() by click button, the exception will be throw in _cancel.Cancel()(main thread).
As you said, every thread has an exception stack(if I understand correctly),and exception will be "created" in the thread who raise it right, it seems like there is no way one thread can throw an exception in the other thread except abort the other thread directly.
Maybe I can implement it like this:
Task.Run(() =>
{
try
{
var currentThread = Thread.CurrentThread;
_cancel.Token.Register(currentThread.Abort);
DoWork();
}
catch (Exception)
{
throw;
}
})
eric881027 27-Feb-15 10:00am View    
I think this solution is not suitable for my problem, this solution can handle the case that task will throw the exception by himself. what I want is there is a long running operation in the task, and user wants to cancel this task by clicking the button like a trigger, it is better to throw an exception from the task after cancel token is notified that it is canceled, cause I want to do the clean up staff outside.
eric881027 10-Aug-11 5:02am View    
Windows service does work, I found I need run the Windows service first,and then add the Service References in the client project.
eric881027 25-Jul-11 2:33am View    
No,I do it all on the code,as the SQL CE does not support the stored procedures
eric881027 25-Jul-11 2:04am View    
Yeah,I am working by this way.