views:

281

answers:

3

I'm working on our continuous integration system, and I'm interested in simulating our systems handling of unexpectedly long compile times. Is there any way to cause the compilation to take a long time to complete? Or perhaps force it into some sort of loop that would take a large amount of time to compile? I'm looking for something as easy as Thread.Sleep() only on the compilation rather than the execution.

How about using preprocessor directives?

Any ideas?

+9  A: 

Here's an MSBuild sleep task that should do the trick. Call it from BeforeBuild target in your .csproj file, or wherever is appropriate for your need.

MSBuild Community Tasks also has a Sleep task, so go with that if you need to use some of their other tasks, which I've found very useful.

Si
+6  A: 

Obviously the Sleep task is the way to go. But if you are interested in ways of making the C# compiler take arbitrarily long, FYI it is possible to encode problems in the source code which force the overload resolution algorithm to execute an O(n^m) algorithm. Choose n and m large enough and you can make the compiler do as much work as you like.

Here's my article on that subject if you're interested.

http://blogs.msdn.com/ericlippert/archive/2007/03/28/lambda-expressions-vs-anonymous-methods-part-five.aspx

Eric Lippert
Awesome! Thanks for the great info.
The Matt
+2  A: 

I had a coworker once who wrote a 16,000 line switch statement. It took forever to compile, and then when he expanded it a bit more it actually broke the compiler. Somehow I'm not sure that's what you had in mind, though.

Russell Newquist