I need to call a method in a Service Reference with the name CancelTransactionByRefPos. This method has the following signature:
int CancelTransactionByRefPos(long refPos, out string resultDescription);
If this method returns '0' the cancel is succeeded. If this method returns another value, the method has to be called again.
I have written a Cancel method which calls the CancelTransactionByRefPos. It is very important the call happens asynchronous because it can take 30 seconds till a response is given.
My method looks like:
public void Cancel(long refPos, GiftCard giftCard, Account_3_2 account)
{
var task = Task.Factory.StartNew(() =>
{
int result;
do
{
string resultDescription;
result = _client.CancelTransactionByRefPos(refPos, out resultDescription);
// logic to log the result with the giftcard and account parameter
} while (result != 0);
});
// task.Wait(); // ######## Uncomment this -> code executes! ########
}
When I Cancel with the task.Wait() part in comment, I get a ThreadAbortException.
When I uncomment the task.Wait() and execute again, everything is doing well but if I have to wait until my task is executed, there is no use calling the method asynchronous.
EDIT
I have also configurated the service reference so it allows generation of asynchronous operations. Same problem.