Reputation: 89
I am working with an embedded linux board (Atmel AT91SAM) with Debian installed. There is a mono application running and its switching an output from GPIO on/off periodicly (like every 500ms) by calling cat by starting a new System Process with bash. After some time I get an "Out of memory" exception and output is not set for a time, after it "recovers itself" after some seconds.
Is there a clean way to dispose the process, or is it done when method is closed automatically?
private void OnTimer1Event(object source, ElapsedEventArgs e)
{
alternateBlinkTimer1.Stop();
alternateBlinkTimer2.Start();
try
{
var processStartInfo = new ProcessStartInfo { FileName = "/bin/bash", Arguments = "-c \"echo 1 > /sys/class/gpio/pioC10/value\"" };
System.Diagnostics.Process process = new Process();
process.StartInfo = processStartInfo;
process.Start();
}
catch (Exception err)
{
log.Error(err.Message);
}
}
Upvotes: 2
Views: 1523
Reputation: 74184
You can try skipping the Process Class and any memory management/garbage collection associated to it by directly use libc's system
.
In your Class that you are defining the OnTimer1Event
method, add a definition to system
:
[DllImport ("libc")]
private static extern int system (string exec);
Then you can:
private void OnTimer1Event(object source, ElapsedEventArgs e)
{
alternateBlinkTimer1.Stop();
alternateBlinkTimer2.Start();
system("echo 1 > /sys/class/gpio/pioC10/value\");
}
Upvotes: 2