How to use ServerTextControl in Windows Services

Typically, Microsoft Windows Services are used to create long-running applications that run in the background for non-UI tasks. TX Text Control is used in such Services to create or convert documents in batch processes or to monitor hot folders to start merging processes when new reports are available.

In the latest version X10, the non-UI component ServerTextControl is available in client and server editions of TX Text Control. In order to use ServerTextControl in a 100% non-UI environment such as a Windows Service, the server license is required.

The following tutorial shows how to create a Windows Service with TX Text Control X10.

  • Open Visual Studio and create a new Windows Service application.

    Windows Services in Visual Studio
  • Find ServerTextControl in the toolbox and drag and drop an instance to your Service designer.

    Windows Services in Visual Studio
  • Switch to code view of Service1.cs and insert the following code to the OnStart method.

    using (TXTextControl.ServerTextControl tx =
        new TXTextControl.ServerTextControl())
    {
        tx.Create();
        tx.Text = "Hello World.";
        // change directory to a folder
        // where user 'LocalService' has access to
        tx.Save("c:\\results.pdf", TXTextControl.StreamType.AdobePDF);
    }
  • Back in the design view, right-click the surface and choose Add Installer from the context menu.

    Windows Services in Visual Studio
  • In the Properties Window of serviceInstaller1, add a Description, DisplayName and ServiceName that will be later displayed in the Services Management Console.

    Windows Services in Visual Studio
  • In the Properties Window of serviceProcessInstaller1, change the Account to LocalService.

    Windows Services in Visual Studio
  • Compile the Service and run a Developer Command Prompt with explicit administrator rights.

    Change the directory to the output directory of your created Windows Service and type in and execute the following command:

    installutil MyTextControlService.exe
    Windows Services in Visual Studio
  • Open the Services Management Console (Administrative Tools -> Services), find the created Service and click Start.

    Windows Services in Visual Studio

    A PDF document has been created in the folder you defined in your Service code.

TX Text Control provides UI and non-UI components and controls for Windows Forms, WPF, ASP.NET and Windows Service applications. Your code is compatible and can be reused in all of these application types.