hi API experts,
I got some code like this:
if
(!Autodesk.Navisworks.Api.Application.ActiveDocument.TryOpenFile(nwfdir + "\\"+ NWFFile))
{....
we use the above code to load 2012 nwf files using navisworks simulate 2012.
My pronblem is that sometimes Navisworks saves "corrupt" nwf files which later on will cause TryOpenFile to go into a never ending "hang" with 100% cpu load. The "if" statement will never get a true or false answer from tryopenfile. I recommend that you don't name a method "tryopen" when it is more like "DoYouFeelLuckyOpen"
LOL
Now my questions
1, should I code a timer that monitors if tryopen fail to open the nwf after 5 minutes ?
2, how do I get if to get out of the 100% load/ hang with out killing roamer.exe (and leaving the addin code that in turn depends on roamer.exe)
Ulrik
Update:
I got a workaround in place now. I start a 5 minute timer before calling TryOpenFile. If TryopenFile does not complete within 5 minutes, the timer event will fire. Inside the event I send an alert and then close roamer. I then know that I have to investigate why Navisworks fail to open the file.
My first go at this problem was to do the load in a new task with a limited run time, but I didn't get that to work so I decided to use a timer instead.
WaitingTime = 5 * 60 * 1000;
// Create a timer with a 5minute interval.
FileLoadTimer = new System.Timers.Timer(WaitingTime);
// Only raise the event the first time Interval elapses.
FileLoadTimer.AutoReset = false;
// Hook up the Elapsed event for the timer.
FileLoadTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
//start the timer
FileLoadTimer.Enabled = true;
NwfOpenOk = Autodesk.Navisworks.Api.Application.ActiveDocument.TryOpenFile(nwfdir + "\\" + NWFFile);
//stop the timer
FileLoadTimer.Stop();
FileLoadTimer.Enabled = false;
FileLoadTimer.Dispose();
FileLoadTimer = null;
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
try
{
Autodesk.Navisworks.Api.Application.MainDocument.Clear();
}
catch (Exception)
{
// do nothing
}
// add send alert code here
//....
System.Timers.Timer timer = (System.Timers.Timer)source; // Get the timer that fired the event
timer.Enabled = false;
timer.Dispose();
timer = null;
Environment.Exit(1);
}
Ulrik