Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

We're creating a WPF app in which we execute python scripts from different Test Stations and show the output in its corresponding output panel, To run the scripts in parallel we are using Task but when we run the scripts in parallel from the stations, We are getting the output of other stations also into the station that is started first, we're using the following code,

C#
private void ZmqStatusListener(string endPoint)
{
    using (Context context = new Context())
    {
        StatusPort = string.Empty;
        TestResultPort = string.Empty;
        using (Socket server = context.Socket(SocketType.REP))
        {
            try
            {
                if (isStatusContextActive == false || isPortChanged == true)
                {
                    server.Bind(endPoint);
                    isStatusContextActive = true;
                }
            }
            catch (ZMQ.Exception ex)
            {
                if (ex.Errno != 100)
                {
                    string IPCPort = _globalParameters.GlbParam.GlbParamIpcStartPort;
                    if (IPCPort == string.Empty)
                    {
                        IPCPort = "0";
                    }
                    if (endPoint == EditorConstants.PortAddress.PortPrefix + IPCPort)
                    {
                        StatusPort = endPoint;
                        TestReultError = EditorConstants.CommonMessageTypes.TestReultError + ex.Message + EditorConstants.CommonMessageTypes.StackTraceMessage + ex.StackTrace;
                    }
                    StopExecOfScript(default(object));
                    isCancelledtask = true;
                    ScriptStatusDesc = new ScriptStatusDesc()
                    {
                        Status = "Failed",
                        statusDescription = "Failed"
                    };
                }
            }
            while (true)
            {
                string message = server.Recv(Encoding.UTF8);
                UpdateTestResults(message);
                server.Send(" ACK", Encoding.UTF8);
                // if (message == "Test Passed")
                //break;
            }
        }
    }
}


and for testing purpose we're breaking the while loop in this code based on a test message we kept in the python script, then we are able to get the output in the respective station correctly but this way we can only run in a synchronous fashion which we don't want as we require to run the test stations in parallel and the while loop should not break as it should be listening for the response.

Thanks,
Abdul Mateen.
Posted
Updated 21-Jul-14 23:51pm
v2

There is a lot missing from your code, but I will hazard a guess that you need to check the socket you send the reply out to. I am guessing that whatever socket you read the inbound message from, the reply is always sent to the first one created.

As each connection is made, hold the socket in a map keyed by a unique id.
When a message is received it must have that unique id.
To send a reply, get the socket for the ID and send to that one only.
 
Share this answer
 
Quote:
We were able to solve the issue by getting clues doing a sample app to reproduce the issue and to first know whether our ClrZmq pattern was correct for us or not and it is correct. The resolution we followed is that when we needed to bind that data to its corresponding View's Model object in its ViewModel so had to retrieve View's DataContext which is of Type ISomeXViewModel for the particular TestStation using an Id of that TestStation we did this cos all of our TestStations are dynamically added and we even store it to be accessed wherever necessary. This issue was caused to due multiple instances of UserControls so we explicitly needed to update the TestStation manually with a little more effort.

Sample Code Snippet

private void BindTestResult(string xmlPayLoad)

{

// converting xmlPalLoad to a class/model object

ITestStationViewModel viewModel = (ITestStationViewModel)((IView)DynamicTestStationsGrid.Children[StationNumber].Content).DataContext;

// IView class has DataContext property so I am type casting the Content which is ContentControl to IView type first and later to ITestStationViewModel

viewModel.TestStationModel = xmlPayLoadModel;

}

Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900