我正在使用Lync Client登录帐户:
_LyncClient = LyncClient.GetClient(true);
if (_LyncClient == null)
{
throw new Exception("Unable to obtain client interface");
}
_LyncClient.SignInDelayed += _LyncClient_SignInDelayed;
_LyncClient.StateChanged += _LyncClient_StateChanged;
_LyncClient.CredentialRequested += _LyncClient_CredentialRequested;
......
try
{
if (_LyncClient.State == ClientState.SignedIn)
{
_LyncClient.BeginSignOut(
ar =>
{
//Set a class field flag so that the application
//shuts down the Lync platform when the application closes
_LyncClient.EndInitialize(ar);
},
null);
}
if (_LyncClient.State == ClientState.Uninitialized)
{
_LyncClient.BeginInitialize(
ar =>
{
//Set a class field flag so that the application
//shuts down the Lync platform when the application closes
_LyncClient.EndInitialize(ar);
//_LyncClient.StateChanged += _LyncClient_StateChanged;
},
null);
}
if (_LyncClient.State == ClientState.SignedOut)
{
if (_callback != null)
_callback.OnSignInStart();
_LyncClient.BeginSignIn(
this.email,
upnOrDomainUserName,
password,
ar =>
{
_LyncClient.EndSignIn(ar);
if (_callback != null)
{
_callback.OnSignInSuccess();
}
},
null);
}
}
catch (NotStartedByUserException h)
{
throw new Exception("Lync is not running: " + h);
}
catch (Exception ex)
{
throw new Exception("General Exception: " + ex);
}
但是,此代码会生成异常:
General Exception: System.InvalidOperationException: Operation is not valid due to the current state of the object. at Microsoft.Lync.Model.LyncClient.BeginSignIn(String userUri, String domainAndUsername, String password, AsyncCallback communicatorClientCallback, Object state)
这会导致什么?我找不到搜索中的任何信息。代码作为Windows服务运行。
由于