WF comes with SqlWorkflowPersistenceService out of the box. But SQL is not always available, or you may just want to try your workflow program with the persistence. I implemented a file based persistence service as attached. Note it does not implement the UnlockWorkflowInstanceState which is needed only when multiple workflow runtime share the instance persistence store.
To use it, simply add the service to the runtime.
FileWorkFlowPersisetenceService fServ = new FileWorkFlowPersisetenceService(".");
workflowRuntime.AddService(fServ);
UnloadOnIdle returns true always in the implementation. So you can see that the workflow is persisted after each call when it becomes idled if you hook up the appropriate event:
workflowRuntime.WorkflowPersisted +=
delegate
{
Console.WriteLine("Workflow persisted");
};