C# 加载项连接已超时,但它';它功能齐全

C# 加载项连接已超时,但它';它功能齐全,c#,add-on,sapb1,C#,Add On,Sapb1,我有一个用c#为SAP B1编程的附加组件。我创建了一个安装程序,并在SAP B1下成功注册了它。但问题是,每当我在SAP B1中启动加载项时,有时它会说“加载项连接超时”。在插件管理器窗口中显示插件失败。但是我可以使用附加组件的所有功能。我唯一不能做的就是,使用“插件管理器”窗口断开插件的连接。但如果我关闭SAP B1,它也会触发应用程序关闭事件 我的问题是,为什么这个消息会出现,即使它工作完全正常?它是否与您在“附加安装程序创建向导”期间必须给出的安装时间有关?因为我的外接程序启动大约需要4

我有一个用c#为SAP B1编程的附加组件。我创建了一个安装程序,并在SAP B1下成功注册了它。但问题是,每当我在SAP B1中启动加载项时,有时它会说“加载项连接超时”。在插件管理器窗口中显示插件失败。但是我可以使用附加组件的所有功能。我唯一不能做的就是,使用“插件管理器”窗口断开插件的连接。但如果我关闭SAP B1,它也会触发应用程序关闭事件

我的问题是,为什么这个消息会出现,即使它工作完全正常?它是否与您在“附加安装程序创建向导”期间必须给出的安装时间有关?因为我的外接程序启动大约需要45秒,而我只给了25秒的安装时间,所以我认为安装时间和外接程序的实际启动时间之间没有联系

如果有专家能解释原因和避免方法,我将不胜感激

我怀疑我与SAP B1的连接方法有问题。然而,对于问题的完整性,可以在下面看到

public void set_application()
{
        SAPbouiCOM.SboGuiApi SboGuiApi = null;
        string sConnectionString = null;

        SboGuiApi = new SAPbouiCOM.SboGuiApi();

        // by following the steps specified above, the following
        // statment should be suficient for either development or run mode
        //System.Convert.ToString(Environment.GetCommandLineArgs().GetValue(1)

        if ((System.Environment.GetCommandLineArgs().Length > 1))
        {
            sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056";  
        }
        else
        {
            sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056"; 

        }

        try
        {
            // If there's no active application the connection will fail
            SboGuiApi.Connect(sConnectionString);
        }
        catch 
        { //  Connection failed
        System.Windows.Forms.MessageBox.Show("No SAP Business One Application was found");
            System.Environment.Exit(0);
        }

        SBO_Application = SboGuiApi.GetApplication(-1);
} 

在发布答案之前,我会给出一些我发现的有价值的信息。 如果将Main()声明为(注意传入Main的参数的差异)

static void Main(String[] Args)  
{   
 sConnection = Args[0];  //This will be the 0 index because Args will only contain the arguments passed  
}  
如果将Main()声明为

因为我的main被声明为
static void main()
,所以我必须如下更改if/else块

if ((System.Environment.GetCommandLineArgs().Length == 0))
{
    sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056";
}
else
{
    sConnectionString = System.Environment.GetCommandLineArgs().GetValue(1).ToString();
}
if ((System.Environment.GetCommandLineArgs().Length == 0))
{
    sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056";
}
else
{
    sConnectionString = System.Environment.GetCommandLineArgs().GetValue(1).ToString();
}