|
@@ -3,6 +3,7 @@ using Emgu.CV;
|
|
|
using Emgu.CV.Structure;
|
|
|
using System.Timers;
|
|
|
using System.Threading;
|
|
|
+using System.Diagnostics;
|
|
|
|
|
|
namespace BBIWARG.Input.InputProviding
|
|
|
{
|
|
@@ -55,21 +56,27 @@ namespace BBIWARG.Input.InputProviding
|
|
|
public void initialize()
|
|
|
{
|
|
|
CurrentFrameID = 0;
|
|
|
-
|
|
|
- watchdogTimer = new System.Threading.Timer(Timer_Elapsed, null, 1000, 1000);
|
|
|
+ watchdogTimer = new System.Threading.Timer(Timer_Elapsed, null, 2000, 1000);
|
|
|
}
|
|
|
|
|
|
+ private bool errorstate = false;
|
|
|
+
|
|
|
private void Timer_Elapsed(object state)
|
|
|
{
|
|
|
checkExitErrorstate();
|
|
|
|
|
|
- if (wrapper != null)
|
|
|
- wrapper.errorstate = true;
|
|
|
+ errorstate = true;
|
|
|
}
|
|
|
|
|
|
+ int startId = 0;
|
|
|
+ Stopwatch startTimeWatch;
|
|
|
+
|
|
|
public void start()
|
|
|
{
|
|
|
- domain = System.AppDomain.CreateDomain(System.Guid.NewGuid().ToString());
|
|
|
+ Console.WriteLine("starting new AppDomain (" + startId +")...");
|
|
|
+ domain = System.AppDomain.CreateDomain("AppDomain-" + startId);
|
|
|
+
|
|
|
+ startId++;
|
|
|
|
|
|
wrapper = (IntelCameraWrapper) domain.CreateInstanceAndUnwrap(typeof(IntelCameraWrapper).Assembly.GetName().ToString(), typeof(IntelCameraWrapper).FullName);
|
|
|
wrapper.init(this);
|
|
@@ -80,30 +87,45 @@ namespace BBIWARG.Input.InputProviding
|
|
|
DeviceStartedEvent(this, new EventArgs());
|
|
|
DeviceStartedEvent = null; //only notify once...
|
|
|
}
|
|
|
-
|
|
|
|
|
|
+ scheduledForRestart = false;
|
|
|
+ startTimeWatch = Stopwatch.StartNew();
|
|
|
wrapper.run();
|
|
|
|
|
|
checkExitErrorstate();
|
|
|
}
|
|
|
|
|
|
+ private bool scheduledForRestart = false;
|
|
|
+
|
|
|
private void checkExitErrorstate()
|
|
|
{
|
|
|
- if (wrapper.errorstate)
|
|
|
+ if (errorstate && !scheduledForRestart)
|
|
|
{
|
|
|
+ if (startTimeWatch != null && startTimeWatch.ElapsedMilliseconds < 5000) {
|
|
|
+ Console.WriteLine("...");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ startTimeWatch.Stop();
|
|
|
+
|
|
|
//we have crashed. Kill the app domain and try again.
|
|
|
- Console.WriteLine("Killing AppDomain...");
|
|
|
+ Console.WriteLine("Killing AppDomain (" + domain.FriendlyName + ")...");
|
|
|
+ scheduledForRestart = true;
|
|
|
+ //wrapper.terminated = true;
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
System.AppDomain.Unload(domain);
|
|
|
- Thread.Sleep(5000);
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
- Console.WriteLine("Could not unload app domain... Still trying to start again...");
|
|
|
+ Console.WriteLine("Could not unload app domain. We will just wait a moment and try to start a new one.");
|
|
|
}
|
|
|
-
|
|
|
- Console.WriteLine("Starting again...");
|
|
|
+
|
|
|
+ domain = null;
|
|
|
+ wrapper = null;
|
|
|
+
|
|
|
+ Thread.Sleep(5000);
|
|
|
start();
|
|
|
}
|
|
|
}
|
|
@@ -118,13 +140,10 @@ namespace BBIWARG.Input.InputProviding
|
|
|
return NewFrameEvent != null;
|
|
|
}
|
|
|
|
|
|
- internal void killAndRestart()
|
|
|
- {
|
|
|
- throw new NotImplementedException();
|
|
|
- }
|
|
|
|
|
|
internal void newFrame(int currentFrameID, Image<Gray, ushort> dImg)
|
|
|
{
|
|
|
+ errorstate = false;
|
|
|
NewFrameEvent(this, new NewFrameEventArgs(currentFrameID, dImg));
|
|
|
}
|
|
|
}
|