views:

49

answers:

1

In a property getter of a C# class I am doing a HTTP GET using HttpWebRequest to some https address. WPF's property binding seems to choke on this. If I try to access the property in a simple method e.g. Button_Clicked, it works perfectly. If I use WPF binding to access the same property, the app seems to be blocked on a socket's recv() method indefinitely.

Is it a no-no to do this sort of thing during binding? Is app in some special state during binding?

Is there an easy way for me to overcome this limitation and still maintain the same basic idea?

+1  A: 

I think it's bad form to do something complex other than returning a value in a 'get' from a property. It's unintuitive to the consumer of the object.

The better idea would be to leave the binding as very dumb (just returning the value), and when the binding should be refreshed, you initiate a background thread to do the web request and then update the property you are using to bind. Then WPF doesn't have to worry about doing a web request when updating it;s bound value.

Tejs
I absolutely agree with your proposal. I was thinking about doing the same thing. It is just that I wanted to see if things could be fixed with less work. Still, I would really love to know the reason for hanging in recv(). I might have a design flaw, but there is obviously some sort of limitation too.
wpfwannabe
Im unsure why it might be hanging, but it's probably because the UI thread is being blocked by that call and WPF has some sort of timeout on the binding. That's just conjecture.
Tejs