2

I generate some code in memory from random size data. This can generate something like 15K classes, and could be even more. The code is stored in a List that I use with the CompileAssemblyFromSource method from the CSharpCodeProvider class.

The thing is, while compiling, I'd like to have a progress report, or maybe an output of whats going on. For the moment, my App just sits there and waits for 5 or 10 minutes.

Is there a way to know how much time this is going to take, or maybe see whats going on. Maybe an other idea ? I hope the answer isn't just a message saying that this process can take a couple of minutes.

svick
  • 236,525
  • 50
  • 385
  • 514
  • Use async/await with Task.Run and https://msdn.microsoft.com/en-us/library/hh193692%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 – JWP May 26 '16 at 08:41
  • Not possible. The only shot you have is splitting the source code across multiple files and compile them each separately. That lets you count down the files. With 15K classes you'll have lots of ways to split code :) – Hans Passant May 26 '16 at 09:37
  • I like the idea. It would be like in C, where i'd compile each Strings in the list individually, and link them all to make a DLL. But, I'm not sure how to do that programmatically. CSharpCodeProvider only compiles straight to a dll. – Hinibi Aremani May 26 '16 at 12:23

1 Answers1

0

As far as I'm aware, there is no way to report the progress of compilation in CodeDOM or the new Roslyn compiler. I think supporting that is a reasonable request, so you might want to consider making a feature request at the Roslyn repo.

In the meantime, you could report progress based on a guess. You can make a guess either based on the input (you're now compiling m kilobytes of code, and compiling n kilobytes usually takes around t seconds, so you expect it to take t / n · m seconds) or based on the last compilation, or both.

(I also considered compiling each file into a separate netmodule and then combine them into one assembly. This would allow you to report progress after each file is compiled. But I think doing this would be too complicated and not worth it just to get progress reporting.)

svick
  • 236,525
  • 50
  • 385
  • 514