Search code examples
c#comstatusfax

FaxComLib FaxJob Queue Status is Always "Pending"


I'm able to send a fax through the COM library FaxComLib (Add Reference -> COM tab -> faxcom 1.0 Type Library) and the fax goes through successfully.

My problem is that while I can send a fax, I can't seem to get an accurate status back from the fax queue. The QueueStatus property of the FaxJob object always returns "Pending."

The environment: Windows 2003 R2 Enterprise w/SP2 -- have also tried on Windows 2008 R2 with same results

Here's my prototype code:

    public void GetFaxStatus(int queueNum)
    {
        FaxServer faxServer = new FaxServer();
        faxServer.Connect("myfaxservername");
        bool isInQueue = false;

        FaxJobs faxJobs = (FaxJobs)faxServer.GetJobs();

        for (int i = 1; i <= faxJobs.Count; i++)
        {
            FaxJob j = (FaxJob)faxJobs.Item[i];
            MessageBox.Show(faxJobs.Item[i].GetType().ToString() + "\r\n" + CreateStatus(j));

            if (j.JobId == queueNum)
            {
                MessageBox.Show("Found Job:\r\n" + CreateStatus(j));
                isInQueue = true;
            }

        }

        if (isInQueue == false)
        {
            MessageBox.Show("Fax is no longer in queue.(...or does not exist)");
        }

        faxServer.Disconnect();
    }

    static string CreateStatus(FaxJob job)
    {
        StringBuilder sb = new StringBuilder();

        sb.AppendLine(string.Format("Billing Code: {0}", job.BillingCode));
        sb.AppendLine(string.Format("Device Status: {0}\r\n", job.DeviceStatus));
        sb.AppendLine(string.Format("Queue Status: {0}", job.QueueStatus));
        sb.AppendLine(string.Format("Display Name: {0}", job.DisplayName));
        sb.AppendLine(string.Format("Fax Number: {0}", job.FaxNumber));
        sb.AppendLine(string.Format("Job Id: {0}", job.JobId));
        sb.AppendLine(string.Format("Tsid: {0}", job.Tsid));
        sb.AppendLine(string.Format("Type: {0}", job.Type));
        sb.AppendLine(string.Format("Page Count: {0}", job.PageCount));

        return sb.ToString();
    }

When I run it for a job that has failed (retry limit was exceeded), I get this:

This result is always returned, no matter what the true status of the job is.

That is the only status I ever get for any fax job; in any status. Am I doing something wrong? Have I configured the fax server wrong? Can you shed any light on my problem for me?

Thanks. -Jason


Solution

  • So, I couldn't come up with anything substantial, but I have made a little progress. If you call FaxJob.Refresh() prior to checking the status, you get a little better result. It appears that a majority of the time, you still get an unhelpful status ("Unknown" in my case), but at least it's not always "Pending." This also returns a "Retries Exceeded" status if the fax fails, but otherwise, "Unknown" is the only status you can get, I guess.

    Here's some sample code:

            if (j.JobId == queueNum)
            {
                MessageBox.Show("Found Job:\r\n" + CreateStatus(j));
                j.Refresh();
                isInQueue = true;
            }