Why sometimes happens System.Threading.ThreadAbortException: Thread was being aborted.
Steps to Reproduce
It can not be reproduced always because it happens very very rarely
Task.Run(() =>
{
try
{
for (byte i = 0; i < seconds * 2; i++)
{
Thread.Sleep(500); //here it happened this ThreadAbortException
if (PaymentLogicBasket.IsBasketTransfered && PaymentProvider.PaymentLogic.IsPaymentClosed)
break;
}
if (InterfaceSettings.CurentPage == InterfacePage.Waiting && Waiting.Instance.ForPay)
InterfaceSettings.SetCurentPage(InterfacePage.PrintCheque, PaymentLogicBasket.IsOpenedBasket ? PaymentLogicBasket.GetBasket() : null);
}
catch (Exception ex)
{
Logs.AppError.Debug(ex.ToString());
}
});
Current Behavior
System.Threading.ThreadAbortException: Thread was being aborted.
Expected Behavior
executing code from start to finish
On which platforms did you notice this
[ ] macOS [*] Linux Arch [ ] Windows
Version Used:
mono 5.2
Stacktrace
[16:38:34:279][Warning][Thread Pool Worker] System.Threading.ThreadAbortException: Thread was being aborted.
at (wrapper managed-to-native) System.Threading.Thread.JoinInternal(System.Threading.Thread,int)
at System.Threading.Thread.Join (System.Int32 millisecondsTimeout) [0x00019] in /opt/tmp/yaourt-tmp-root/aur-mono-stable/src/mono-5.16.0.179/mcs/class/referencesource/mscorlib/system/threading/thread.cs:708
at Terminal.Payment.UI.Commons+<>c__DisplayClass189_0.<PayOrdinaryPayment>b__1 () [0x000ae] in /media/destructor/Documents/Projects/CSharp/TerminalClient_v7/GUI/Standard/TerminalUI/Commons.cs:2584
RUNTIME CONTINUED TO EXECUTE AFTER THIS ThreadAbortException!!! I want to understand why thread was aborted. And what may I do in order to thread works fine!
During normal runtime shutdown all background threads are being aborted. I suspect this is the culprit
During normal runtime shutdown all background threads are being aborted. I suspect this is the culprit
:-1: Application has continued to work. Runtime was not shutdown
AppDomain unloading can also trigger aborts for threads running code in that domain.
AppDomain unloading can also trigger aborts for threads running code in that domain.
What is unloading? Application continue to work!
AppDomain unloading can also trigger aborts for threads running code in that domain.
What is unloading? Application continue to work!
Again it happened but this time with Thread class
[08:52:15:324][Warning][31] System.Threading.ThreadAbortException
at (wrapper managed-to-native) System.Net.Sockets.Socket:Connect_internal (intptr,System.Net.SocketAddress,int&,bool)
at System.Net.Sockets.Socket.Connect_internal (System.Net.Sockets.SafeSocketHandle safeHandle, System.Net.SocketAddress sa, System.Int32& error, System.Boolean blocking) [0x00006] in /media/flash/mono-5.2.0.224/mcs/class/System/System.Net.Sockets/Socket.cs:1160
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00079] in /media/flash/mono-5.2.0.224/mcs/class/System/System.Net.Sockets/Socket.cs:871
at Terminal.Providers.Network.AsyncTelemetry.AsyncTcpClient.<Connect>b__33_0 () [0x00159] in /media/destructor/SSD/Projects/TerminalClient_v7/RegulTerminal.Providers.Network/AsyncTelemetry/AsyncTcpClient.cs:119
I think that it exists something bad in this managed-to-native
Did you fin a solution for this ?
No I did not. I notice that it happens often when use Task.Run() with Thread.Sleep() inside body. I've even found some recommendation from Microsoft to not use Task for long time execution. Therefore I decide to use new Thread().Start() instead Task.Run() but it resolves problem particularly