I built a Client class that inherits from the ClientBase class as part of my WCF Client. I am trying to figure out how to ensure that the Connection does not need to be re-established. I did see the CommunicationState enumeration has the stuff I need, along with the ClientBase.State, however I'm not sure how to get it to wait if it's in the Opening state, or something similar... Basically if it's Opened and not locked I'm good to go, but if it's doing something like Opening or Created or whatnot, I don't wanna have to create a new one. Alternatively, is there any way to remove the Timeout all-together and just have it close the connection when the application closes?
private static MyClient _client;
public static MyClient Client
{
get
{
if (_client != null)
{
lock(_client)
{
//How do I ensure that I can return a MyClient that is in Opened state??
//If it's doing something like Opening I don't wanna create a new one...
}
}
}
}