C# ProcessXmlTicketAsync

We are writing some C# code using the Web API of Recognition Server 4.0. However, we are having difficulty in getting the code to work when use the Async call (client.ProcessXmlTicketAsync). We want to use asynchronous calls rather than synchronous due to the size and quantity of documents being processed. We have successfully written code for the synchronous calls.

We understand how to create the XmlTicket and workflow string retcode = client.ProcessXmlTicketAsync( xmlTicket, workflow); returns us a JobId as we expect.

What we don’t understand is how to wait for the result. Normally on an asynchronous process, a callback function would be supplied. Are we supposed to just start a loop containing a wait so that at regular intervals we call GetJobState until the return state is JS_Published (although the state after JS_publishing seems more relevant). We still do not understand how to get the XmlResult object

Does anyone have an example of C# code that performs asynchronous processing in Recognition Server?

Was this article helpful?

0 out of 0 found this helpful



  • Avatar
    Ivan Korneev
    jobId = MyClientObject.StartProcessFile(server, selectedWorkflow, fileContainer);

    for (int i = 0; i < 10;="">) {
    RS.JobStateEnum state = MyClientObject.GetJobState(server, jobId);
    if (state == RS.JobStateEnum.JS_NoSuchJob || state == RS.JobStateEnum.JS_Complete) {

    RS.XmlResult xmlResult = MyClientObject.GetJobResult(server, jobId, null);
    if (xmlResult != null) {
    Debug.WriteLine(fileName + " processed");
    if (xmlResult.IsFailed) {
    Debug.WriteLine("Recognition failed");
    } elseif (MyClientObject.GetJobState(addressField.Text, jobId) == RS.JobStateEnum.JS_NoSuchJob) {
    Debug.WriteLine(fileName + " failed, server side was rebooted, please send job again");
    } else {
    // this job is still performing on server
    // you can
    // 1) wait more time to complete
    // 2) DeleteJob and send it again after timeout in 10 minutes or more,
    // 3) DeleteJob and raise error

    For XmlTicket code is almost same
  • Avatar
    Ivan Korneev
    private FinishedRequests requests = new FinishedRequests();
    private void ClientObject_OnJobComplete( string id, RS.XmlResult result ) {
    requests.Add( id, result );

    private RS.Client client = new RS.ClientClass();
    client.OnJobComplete += new RS.DIClientEvents_OnJobCompleteEventHandler( ClientObject_OnJobComplete );

    string jobId = client.ProcessXmlTicketAsync( internalTicket, workflowName );
    RS.XmlResult internalResult = waitForResult( jobId );

    private RS.XmlResult waitForResult(string jobId)
    while (true)
    RS.XmlResult result = requests.Get(jobId);
    if (result != null)
    return result;

Please sign in to leave a comment.