I have C# code here:
dlgCardLimit dlg = new dlgCardLimit(GetCardLimit);
IAsyncResult res = dlg.BeginInvoke(cardNo, null, null);
res.AsyncWaitHandle.WaitOne(timeOut);
if (res.IsCompleted)
{
cardLimit = dlg.EndInvoke(res);
}
else
{
//Terminate the async thread.
}
In "Else" case, how can I terminate the thread that IAsyncResult is pointing?
Your dlgCardLimit class should have another method that would allow a graceful cancellation of the pending operation, such as Cancel or Close so as to give a chance for Gracefully handling the error. The thread on which this is running is hidden from you.
Checkout the Socket.EndReceive for a similar pattern in cancelling a pending operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With