Printer Maestro Service Randomly Stops Folgen

0
Avatar
Legacy Poster

Hi,

 

To give you abit of background on what I'm doing. I've written an application which uses BarTender to print out labels and save image to disk. So, here is code I've written for printing our labels:

/// <summary>
/// PS: Print a bar tender report file.
/// </summary>
/// <param name="printerName">This must be executed via print share or direct printer name.</param>
/// <param name="barTenderReportFileName">The filename of the bar tender report file. (.btw)</param>
/// <param name="numberOfCopies">The number of copies you want.</param>
/// <param name="lstParameters">Exposed to</param>
/// <returns>
///  0  Successful.
/// -1  Printer name not defined.
/// -2  File does not exist.
/// -3  Requires a quanitiy greater than zero.
/// -4  Failure.
/// </returns>
public int PrintMaterialLabelEx(string printerName,
                        string barTenderReportFileName,
                        int numberOfCopies,
                        Dictionary<string, string> lstParameters)
{
    // PS: The printer must be defined.
    if (printerName == string.Empty)
        return -1;

    // PS: An valid bar tender report file must be specified.
    if (File.Exists(barTenderReportFileName) == false)
        return -2;

    // PS: The printer must at least require 1 copy of the files.
    if (numberOfCopies <= 0)
        return -3;

    // PS: We must have a material code, otherwise we wouldn't able to print a material label.
    string materialCode = lstParameters["MaterialCode"];

    // PS: Let's generate and print our label.
    using (Seagull.BarTender.Print.Engine btEngine = new Engine(true))
    {
        // PS: Open the customer or default label with defined printer.
        LabelFormatDocument labelFormatDocument = btEngine.Documents.Open(barTenderReportFileName, printerName);

        // PS: Loop through all parameters on the bar tender label. 
        foreach (var parameter in lstParameters)
        {
            foreach (var str in labelFormatDocument.SubStrings)
            {
                if ( str.Name == parameter.Key )
                    str.Value = parameter.Value;
            }
        }

        // PS: Loop through all database connection queries.
        foreach (var query in labelFormatDocument.DatabaseConnections.QueryPrompts)
        {
            if (query.Name == "MaterialCode")
                query.Value = materialCode;
        }

        // PS: Print out the label by user-defined amount.
        labelFormatDocument.PrintSetup.IdenticalCopiesOfLabel = numberOfCopies;

        string fileName = Path.GetFileName(barTenderReportFileName);

        // PS: Generate a unique job name.
        string jobName = String.Format("{0}_{1}_{2}",
                            fileName,
                            materialCode,
                            Guid.NewGuid());

        // PS: Let's setup print options.
        labelFormatDocument.PrintSetup.SelectRecordsAtPrint = false;
        labelFormatDocument.PrintSetup.EnablePrompting = false;

        Messages messages;
        // PS: We don't want to wait too long as we don't want to timeout in ABAP.
        Seagull.BarTender.Print.Result result = labelFormatDocument.Print(jobName, 1000, out messages);

        if (result == Result.Failure)
        {
            foreach (var message in messages)
            {
                Log("Error.txt", message.Text);
            }

            return -4;
        }

        string newFileName = "D:\\inetpub\\SapPrint\\Temp\\" + jobName;

        labelFormatDocument.SaveAs( newFileName + ".btw", true );

        labelFormatDocument.ExportImageToFile( newFileName + ".jpg", 
                                            ImageType.JPEG, 
                                            ColorDepth.ColorDepth24bit, 
                                            new Resolution(300), 
                                            OverwriteOptions.Overwrite );

        // PS: Don't save any changes.
        btEngine.Stop( SaveOptions.DoNotSaveChanges );
    }

    return 0;
}

Every day or so the Printer Maestro service stop running so have to restart it. Just wondering what causes it as then the application throws an exception of:

Printer: SI4-POD060
Job ID: 347
Status: Unknown
Description: Print job status is unknown because the Printer Maestro Service is not running on the computer the printer is attached to.

So, I have to run command to get it back working:

net start "Printer Maestro"

The event viewer doesn't give any useful information as it just shows an warning with following message:

Local service is not running

I can't seem to work out what's causing it to crash. Any help or suggestions would be great. Thanks.

 

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.