After reading a recent MSDN Magazine article about the task scheduler, I was hoping (and really very excited) that using this would benefit my use of the WCF proxies created by WCF.
I was hoping to get some of the following benefits:
- 1) The ability to interrupt WCF (I do not expect this to stop the operation on the server - I just wanted to report that āI cannot want to get the result for this task.ā This is especially true for the user interface, where someone repeatedly chooses grid items that cause service calls.)
- 2) The ability to run a task at some point, in addition to when it was created . Iām not sure that I really need it, I just thought it would be nice to create a task, and not immediately start it. In the end, I thought it was all a matter of tasks.
- 3) Binding properties - so I can bind my WCF interface to
IsCompleted and let the task class abstract the internal work items from my user interface. - 4) The ability to abstract from the operation - mockery, blah blah blah, future refactoring, etc.
However, it seems that I am not getting ANY of these benefits.
- 1) There is no interrupt function in the Task, which seems really strange to me.
- 2) The only overload with which I could work with
Task.Factory.FromAsync<> is the one shown below. This immediately starts the webservice operation (as seen from Fiddler) and prevents me from starting the call later. - 3) The task does not implement
INotifyPropertyChanged , so I cannot bind it to the user interface. - 4) This is one of the dead in the water, as the other 3 benefits do not occur: - (
Sooo .... I'm just wasting time trying to get WCF generated proxies working with Tasks, or am I missing something.
// WCF client var client = new ShoppingCartClient(); // create task var t = Task.Factory.FromAsync<GetOrderDetailsMsgOut>( client.BeginGetOrderDetails(new GetOrderDetailsMsgIn() { OrderId = 12345 }, null, null), client.EndGetOrderDetails); t.ContinueWith(x => { var order = x.Result.Order; // do something with order });
source share