What I can provide to you with certainty is a concrete alternative that will produce the same output but instead of using CopyFromScreen
using platform invoke
to interop with the Windows API directly. You can find a full example here, curtosy of Hans Passant as a response to a question here.
I can't however, tell you with certainty why you're experiencing the exception but I can deduce from other sources such as this thread (incidentally featuring Hans again as nobugz) and from my own experiences that CopyFromScreen
is buggy and in this case, could be suffering from a memory leak. Considering the thread I linked, what version of the .NET Framework is your target framework?