I’ve a single statement running on WPF application
that takes a long time (by long I mean 5000ms , which is too long )
i need to run this statement in thread but ,
i need this thread return bool value indicate status
if it successfully execute it return true
else for Exception or i forced to stop this single statement return false
What is the best way to accomplish this?
and again it single statement
and how to safety abort “force to end execute statement “
You might have some luck taking a look at the
System.Threading.Tasks.Task<TResult>class. Creating it simply means passing it aFunc<TResult>object, so it can be one statement or many. It can handle a return value (that’s the difference between it andSystem.Threading.Tasks.Task). You can also use aCancellationTokento handle a forced stop. See this article for more on that.