Search code examples
c#visual-studiomatlabc#-4.0matlab-deployment

Rogue 40-second wait when loading a Matlab assembly ... how to diagnose the cause?


I've got a very odd problem: I've compiled some Matlab code into an assembly. I instantiate the class with the following C# line:

MatPhiLib temp = new MatPhiLib(); // This line takes 40 seconds to execute.

The very first time this line is called, it always takes exactly 40 seconds to execute. Subsequent calls are instantaneous. Something has changed, because it didn't take this long when I last looked at the code 4 months ago.

Can an expert recommend a way to get some visibility to see whats going on here?

UPDATE:

Noticed that UltraEdit (my editor) also takes precisely 40 seconds to start up the first time as well. I think that there is some link there, as this never used to happen either.

UPDATE:

Found the problem: it was my new NetGear Stora NAS causing the problem with obscene network timeouts. When I unplugged it, everything started to work like greased lightning.

May the fleas of a thousand camels infest the armpits of the donkey-brained guy responsible for that epic engineering design fail.


Solution

    1. Early in the 40 second wait period, breaking in to the running process (Debug → Break All).
    2. Open up the Call Stack window (Debug → Windows → Call Stack).
    3. If you are using the MatLib assembly as an external library rather than a project in your solution, right click the Call Stack window and select Show External Code on the context menu.
    4. Open up the Threads window (Debug → Windows → Threads).
    5. Work your way through the threads, selecting them one by one and looking at the Call Stack window. You should be able to see, from the top few frames, what each of the threads is doing -- you should be able to see where in the MatLib code the the delay is caused. (Threads in wait handles are waiting on other threads to complete work or are idle waiting for other threads to create work for them to process.)

    My guess is that the library will be attempting to make a network call of some sort and 40 seconds is the timeout on this call. You should be able to use the information you learn from the above steps to track down the problem in the library.