Hi all, Hopefully you can help.
Scenario WPF Application calling a wcf Service to buy products etc... A customer can select 20 products in the UI and press buy,now for each product that is processed I need to report a status EG("OK","Out of stock","Busy" etc...) I have a txtReportProgress that is bind to a BuyCommand.
Problem Even though everything seems to work ok and I receive a notification for each product processed it gets all out sync and not actually reporting the steps in the correct order. I think this is todo with the fact that I have NOT implemented threading but I dont know how to do it. I have read i can use "Dispatcher" i/o background worker but cannot make it work. Noddy example here to give you an idea.
Can you help me and give me some pointers?
---CustomerViewModel
public ICommand BuyCommand
{
get
{
if (BuyCommand == null)
{
BuyCommand = new RelayCommand(param => Buy(), param => CanBuy);
}
return BuyCommand;
}
}
private void Buy()
{
ReportProgress("Buying Progress is starting");
ProductStatus status=myService.IsProductAvailable();
myService.ProcessProducts(); //For each product that is processed service does a callback and NotificationReceivedfromService is fired.THIS WORKS!!
ReportProgress(status);
var result =DoSomethingElse();
ReportProgress(result);
}
void NotificationReceivedFromService(object sender, StatusEventArg e)
{
//update the UI
ReportProgress(e.Message);
}
static bool CanBuy
{
get
{
return true;
}
}
public string CustomerLog
{
get { return _customerModel.CustomerLog; }
set
{
_customerModel.CustomerLog = value;
base.OnPropertyChanged("CustomerLog");
}
}
internal void ReportProgress(string text)
{
CustomerLog += text + Environment.NewLine;
}