It's a weird situation here :) , I have implemented this code in my fragment to scan TCP Ports
in multithread environment
, it crash when debugging
, and sometimes crash in release mode
too with thoose messages :
E/art (12972): Nested signal detected - original signal being reported
F/art (12972): art/runtime/fault_handler.cc:117] Check failed: !initialized_
tried to set Target
Android to 23
that didn’t work.tried running
adb shell setprop debug.mono.env MONO_DEBUG=soft-breakpoints
that didn’t work.tried to compile using different
Android API's Versions
ANY IDEA WHY IS THIS HAPPENING ??
HERE IS MY CODE:
public void start()
{
for (int i = 0; i < 50; i++)
{
Task.Run(() => RunScanTcp());
//ThreadPool.QueueUserWorkItem(RunScanTcp);
//Thread thread = new Thread(new ThreadStart(RunScanTcp));
//thread.Start();
}
}
public void RunScanTcp()
{
while (abort != true)
{
port = port + 1;
Log.Info("PORT SCANNER", port.ToString());
}
}
public class PortList
{
private int start;
private int stop;
private int ports;
private static readonly object _syncRoot = new object();
public PortList(int starts, int stops)
{
start = starts;
stop = stops;
ports = start;
}
public bool MorePorts()
{
lock (_syncRoot)
{
return (stop - ports) >= 0;
}
}
public int NextPort()
{
lock (_syncRoot)
{
if (MorePorts())
{
return ports++;
}
return -1;
}
}
}
Im compiling using :
Android Version (Android 7.1 Nougat)
Minimum Android Version :
Android 4.1 (API Level 16 - Jelly Bean)
Target Android Version:
Compile Using SDK Version
UPDATE :
After Visual Studio Update 15.2 (26430.12)
, and Xamarin 4.5.0.476
- 30/05/2017
(dd/mm/yyyy) the application crashed
while is connected to debugger
too...
Here is the debugger output :
referenceTable GDEF length=814 1
referenceTable GSUB length=11364 1
referenceTable GPOS length=47302 1
referenceTable head length=54 1
referenceTable GDEF length=428 1
referenceTable GSUB length=2302 1
referenceTable GPOS length=43252 1
referenceTable head length=54 1
referenceTable GDEF length=808 1
referenceTable GSUB length=11364 1
referenceTable GPOS length=49128 1
referenceTable head length=54 1
referenceTable GDEF length=808 1
referenceTable GSUB length=11364 1
referenceTable GPOS length=47320 1
referenceTable head length=54 1
05-31 04:31:51.590 F/art (17427): art/runtime/fault_handler.cc:117] Check failed: !initialized_
Thank's All of you ...
Apps on Android can crash because of low storage space, too many apps running simultaneously, a weak internet connection, or not having the proper app updates installed.
The easiest way to fix an app that keeps crashing on your Android smartphone is to simply force stop it and open it again. To do this, go to Settings -> Apps and select the app that keeps crashing. Tap on the app's name and then tap on 'Force stop'. Now try opening the app again and see if it works well.
Xamarin support will end on May 1, 2024 for all Xamarin SDKs. Android 13 and Xcode 14 SDKs (iOS and iPadOS 16, macOS 13) will be the final versions Xamarin will target.
Go to “Settings” > Apps > Find the app that keeps crashing. Enter the information of the App, and tap on “Force Stop”. Then try to open the app again and see if it still crashes.
As you described it is working without that part of your code ... so the error must be somewhere in your code.
let's look at it.
public void start()
{
for (int i = 0; i < 50; i++)
{
Task.Run(() => RunScanTcp());
}
}
public void RunScanTcp()
{
while (abort != true)
{
port = port + 1;
Log.Info("PORT SCANNER", port.ToString());
}
}
In the start
method you start 50 tasks - and not await
ing any of them - which means, that possibly all tasks run in parallel (at least definitely some tasks try to access port
at the same time).
What those tasks execute is a method that accesses port
which must be a field of the containing class.
Accessing a shared field from multiple tasks / threads is never a good idea without a lock.
Try using the following code instead (if you really need the parallel tasks for some reason).
public class YourClass
{
private bool abort;
private int port;
private object portLock = new object();
public void start()
{
for (int i = 0; i < 50; i++)
{
Task.Run(() => RunScanTcp());
}
}
public void RunScanTcp()
{
while (abort != true && this.port < int.MaxValue)
{
lock (this.portLock) {
port = port + 1;
Log.Info("PORT SCANNER", port.ToString());
}
}
}
}
Possibly a better approach is to only use one task and somewhere await
it.
public class YourClass
{
private bool abort;
private int port;
private object portLock = new object();
public Task start()
{
return Task.Run(() => RunScanTcp());
}
public void RunScanTcp()
{
lock (this.portLock) {
while (abort != true && this.port < int.MaxValue)
{
port = port + 1;
Log.Info("PORT SCANNER", port.ToString());
}
}
}
}
If that solves your current problem you might want to add another question about how to properly solve what you're actually trying to solve (since your current code basically just increments the port
until it is aborted or the app crashes (since it counted above the Int32
MaxValue)
So I came across an issue just like that with Xamarin and VS. it turns out that not all error are logged into the VS debugging console, but they are in the device log. What I had to do that time was to go and use the emulator on my machine and run it while having the device log ON. and stopped the logging right after the crash. In that log it was clear what the issue was (which in my case was a misconfigured permission). Hope that helps.
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