Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF CLR Python2.7 Tasks
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,
 
        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 21-Jul-14 22:37pm
Edited 22-Jul-14 0:51am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 17 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100