I've been looking at the ability to pause and resume a .Net application as of late, particularly with an eye towards being able to pause an application, store its state, and launch it again later.
I've been looking at the options provided by writing a custom CLR Host, an arcane art to be sure. It appears that a custom host can provide its own implementations for tasks, memory management, locks, etc. So from this it looks like I might be able to create a custom CLR Host that can pause and resume an application via ICLRTask, but I'm not sure the interfaces provided have enough hooks to pause all the tasks, store the entire program state to disk, and then bring the application back to life at a later point. Can someone definitively tell me that it's not possible at all? I also don't mind if it's only possible for a small subset of applications, I'm just curious about the possibilities here.
Sorry to have to rain on your parade, but that's not going to fly. The ICLRTask interface was added at the express request from the SQL Server team. They support the SQLCLR host, a custom hosting of the CLR to allow programmers to write managed code in stored procedures. They asked the CLR team to break the hard link between a managed Thread and an operating system thread, ProcessThread in the current framework. With the intention of implementing managed threads as fibers, a core feature of SQL Server at the time.
That did not actually happen, they couldn't get it reliable enough and gave up on the project. And the project was rapidly running out of reasons to make it work, fibers are no match for multi-core cpus with their own L1 cache.
Which doesn't have a heckofalot to do with what you are trying to accomplish. By far the toughest nut to crack, beyond reliably capturing the process state, is that you can't really deal with threads that are executing native code. Particularly the kind that pinvoked a winapi function and are blocking on a kernel driver to finish an I/O request. You can't capture the kernel state, nor do you have a hook. Adding hooks to the pinvoke marshaller would make it too slow. Hibernate is a system feature, it can't be a process feature.