Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Answered Scheduler.CurrentThread works but .NewThread doesn't?

  • 24 เมษายน 2555 14:02
     
      มีโค้ด

    Hi,

    I am new to Reactive Extensions and would like to process a List of items in parallel. I would like to call a WCF Service from my processing thread but can only get it to work using the "CurrentThread"? My goal is to process each item on a different thread and eventually in parallel? Can this be done when calling a WCF Service?

    Here is my code:

     var query = from row in dataRows select row;
     var observableQuery = query.ToObservable(Scheduler.CurrentThread);
     observableQuery.Subscribe(ProcessLocation, LocationError, LocationProcessingCompleted);

    Here is the code that is used to call the WCF Service and insert my List item:

    static void ProcessLocation(DataRow locData)
    {
        var locReq = new LocationRequest()
    	        {
    		RowData = LocationManager.CreateKeyValueLocation(dataRow: locData).ToArray(),
    		FileId = LocationManager._fileId
    	        };
        // Call the WCF Service to add a new location
        using (var locClient = new ServiceClient())
        {
    	var response = locClient.AddLocation(locReq);
        }	
    }

    For some reason the Rx code will only make one call when "NewThread" or "ThreadPool" is used and that call will throw an exception (Exception try/catch was removed from this example).

    Has anyone called a WCF Service from inside the processing function? Am I doing it correctly? Should I be using some sort of Async code to achieve Parallel processing of my List?

    tnx,

    SD. 

ตอบทั้งหมด

  • 24 เมษายน 2555 14:34
     
     คำตอบ
    Looks like I might have found the solution I was looking for PLINQ.
    • ทำเครื่องหมายเป็นคำตอบโดย Shadow_dog007 24 เมษายน 2555 14:34
    •