函数调用dll导致程序挂起

时间:2013-05-01 09:39:58

标签: c# wpf dll

我遇到一个问题,我的代码在调用连接到服务器上的应用程序的Dll中调用LogIn函数时会冻结但不会经常发生。这仅在我登录时发生,并且在没有连接的情况下进行连接,然后在超时之前重新连接(重复尝试LogIn),然后再次尝试登录,此时它将永远位于对Dll的函数调用中。一旦从服务器获得所需数据,每个LogIn都会跟随一个LogOut。这是Dll功能的引入方式:

    [DllImport("SafeComDLLs\\scApi.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.Cdecl)]
    private static extern int sc_LoginByLogon(string szlpAddr,string szuserLogon,string szPassword);

这是我用来连接服务器的代码:

    public int LogIn(string ipAddress, string userName, string password)
    {
        int result = -1;

        try
        {
             result = sc_LoginByLogon(ipAddress, userName, password);
             if (result == 0)
                 _log.Info("Log in Success");
             else
                 _log.Error("Log in failed, error message : " + result.ToString());
        }
        catch (Exception e)
        {
            _log.Error("sc_LoginByLogon failed with exception : " + e.Message);
        }
        return result;
    }

正如您所看到的,我捕获了异常,但因为没有抛出异常,代码就在这一部分:

         result = sc_LoginByLogon(ipAddress, userName, password);

0 个答案:

没有答案
相关问题