Scheduler.CurrentThread works but .NewThread doesn't?

已答覆 Scheduler.CurrentThread works but .NewThread doesn't?

  • 2012年4月24日 下午 02: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. 

所有回覆

  • 2012年4月24日 下午 02:34
     
     已答覆
    Looks like I might have found the solution I was looking for PLINQ.
    • 已標示為解答 Shadow_dog007 2012年4月24日 下午 02:34
    •