Background tasks in MVC and IIS

2 min read As you might’ve noticed, keeping threads running after a request returns, for processing post operational tasks (such as performing analytics on a file that was uploaded, etc) don’t always complete in a web project.
There are several issues with spawning threads in the context of an ASP.NET project. Phil Haack’s post explains the issues in more detail. The following classes solve the problem of IIS killing threads before they complete.

Accessing indesign server from C# via COM

2 min read I’ve done quite a bit of searching on InDesign Server, and according to the people at Adobe, C# isn’t “dynamic” enough for use with their API. But obviously, they were looking at Java documentation mislabeled C# or at some very old books. Anyway, a lot of things in their documentation are misleading, so I will attempt to get you started on the right path to using InDesign Server CS6 from C# via COM objects.

InDesign Server registers it’s COM objects when it starts up, and only makes them available in the context in which it was started up. I have yet to figure out why they do this, or how to get around it, but note that if you’re logged onto the computer with the same user twice and start it from one of them, the second instance can’t access the first, nor can it start its own InDesign instance. This information is very important if you’re trying to access it from a service or from within IIS.

Asuming everything went alright, you can now begin to create your project. You first need to add a COM reference to InDesignServer and then import

using InDesignServer;

Now to create the application and make a few calls.

InDesignServer.Application app;
InDesignServer.Document doc;
try
{
    app = new InDesignServer.Application();
    try
    {
        doc = app.Open(Path.Combine(@"C:temp", "inDesignDoc.indd"),
        InDesignServer.idOpenOptions.idDefault);
        doc.Export(InDesignServer.idExportFormat.idPDFType, Path.Combine(@"C:temp",
        "indesign.pdf"), Type.Missing, false, Type.Missing, false);
        doc.Close();
        doc = null;
    }
    catch {}
}
catch {}