Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 导入C+时的FATAlexecutionEngineer错误+;动态链接库 我编写了一个应用程序,它调用C++编写的DLL中的方法。它是一个WinForms应用程序,其中有一个自托管的WCF服务。WCF方法之一是 定期在2-3秒内调用。当仅执行WCF部分时,不会出现问题。当只调用SDK函数时,问题不会出现。然而如果 我启动WCF客户端,定期调用我的方法,同时执行一些SDK函数,10秒后出现FatalExecutionEngineError(System.ExecutionEngineeException)。 引发异常,应用程序崩溃。我真的不知道问题出在哪里,也不知道如何解决。我怀疑它与SDK有某种联系,但我不确定,只是一个例子 感觉阅读这里的相关答案,也许方法导入是错误的?以下是我到目前为止得到的信息:_C#_C++_.net_Wcf - Fatal编程技术网

C# 导入C+时的FATAlexecutionEngineer错误+;动态链接库 我编写了一个应用程序,它调用C++编写的DLL中的方法。它是一个WinForms应用程序,其中有一个自托管的WCF服务。WCF方法之一是 定期在2-3秒内调用。当仅执行WCF部分时,不会出现问题。当只调用SDK函数时,问题不会出现。然而如果 我启动WCF客户端,定期调用我的方法,同时执行一些SDK函数,10秒后出现FatalExecutionEngineError(System.ExecutionEngineeException)。 引发异常,应用程序崩溃。我真的不知道问题出在哪里,也不知道如何解决。我怀疑它与SDK有某种联系,但我不确定,只是一个例子 感觉阅读这里的相关答案,也许方法导入是错误的?以下是我到目前为止得到的信息:

C# 导入C+时的FATAlexecutionEngineer错误+;动态链接库 我编写了一个应用程序,它调用C++编写的DLL中的方法。它是一个WinForms应用程序,其中有一个自托管的WCF服务。WCF方法之一是 定期在2-3秒内调用。当仅执行WCF部分时,不会出现问题。当只调用SDK函数时,问题不会出现。然而如果 我启动WCF客户端,定期调用我的方法,同时执行一些SDK函数,10秒后出现FatalExecutionEngineError(System.ExecutionEngineeException)。 引发异常,应用程序崩溃。我真的不知道问题出在哪里,也不知道如何解决。我怀疑它与SDK有某种联系,但我不确定,只是一个例子 感觉阅读这里的相关答案,也许方法导入是错误的?以下是我到目前为止得到的信息:,c#,c++,.net,wcf,C#,C++,.net,Wcf,WCF等级: [ServiceContract] public partial interface IWCFSample { [OperationContract] string GetData(string param); } [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] public partial class WCFSample : IWCFSample { #region

WCF等级:

[ServiceContract]
public partial interface IWCFSample
{
    [OperationContract]
    string GetData(string param);
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public partial class WCFSample : IWCFSample
{
    #region Delegates

    public delegate string OnGetDataDelegate(object sender, string getDataParam);

    #endregion Delegates

    #region Events

    public event OnGetDataDelegate OnGetData;

    #endregion Events

    public string GetData(string serializedGetDataParam)
    {
        string res = string.Empty;
        try
        {
            if (OnGetData != null)
            {
                res = OnGetData(this, (serializedGetDataParam));
            }
        }
        catch
        {
            throw;
        }
        return res;
    }
}
像这样发起的:

    private ServiceHost _serviceHost;
    private WCFSample _samplewcf;

    private void Form1_Load(object sender, EventArgs e)
    {
        _samplewcf = new WCFSample();
        _samplewcf.OnGetData += samplewcfOnGetData;

        _serviceHost = new ServiceHost(_samplewcf);
        _serviceHost.Open();
        bw = new BackgroundWorker();
        bw.WorkerSupportsCancellation = true;

        bw.DoWork += (o, args) =>
        {
            WCFSampleClient client = new WCFSampleClient();
            while (true)
            {
                if (bw.CancellationPending)
                {
                    return;
                }

                client.GetData(DateTime.Now.ToString());
                Thread.Sleep(200);
            }
        };
        bw.RunWorkerAsync();
    }

    private string samplewcfOnGetData(object sender, string getDataParam)
    {
        richTextBox1.Text += "GetData Called - " + getDataParam + "\n";
        richTextBox1.SelectionStart = richTextBox1.Text.Length;
        richTextBox1.ScrollToCaret();
        return getDataParam;
    }
<> > C++相关部分相当长,但这里是我使用的导入。

int OpenDevice (char* strUSBName, int iPortNum )

Imported as:
[DllImport("TP9000.dll")]
public static extern int OpenDevice(string USBNam, int portnum);


int CheckFeeder (int* nCheck)

Imported as:
[DllImport("TP9000.dll")]
public static extern int CheckFeeder(ref int pStatus);


int DP_GetSensorStatus (BYTE *pRailStatus, BYTE *pFeedRollerStatus, BYTE *pTraySensorState)

Imported as:
[DllImport("TP9000.dll")]
public static extern int DP_GetSensorStatus(ref byte pRailStatus, ref byte pFeedRollerStatus, byte[] pTraySensorState);


int PathSenser(int *pStatus)

Imported as:
[DllImport("TP9000.dll")]
public static extern int PathSenser(ref int p1);


int CheckRibbonEx( int *nRibbon, int *nTagRibbon)

Imported as:
[DllImport("TP9000.dll")]
public static extern int CheckRibbonEx(ref int nRibbon, ref int nTagRibbon);


int N_EndOfPrint(int nPanel, int *pPanelCount, int *pJobNo)

Imported as:
[DllImport("TP9000.dll")]
public static extern int N_EndOfPrint(int p1, ref int p2, ref int p3);


int N_PrintJobStatus (int *pJobStatus )

Imported as:
[DllImport("TP9000.dll")]
public static extern int N_PrintJobStatus(int[] p1);
更新:

最后一次导入似乎是错误的:

int N_PrintJobStatus (int *pJobStatus )

Imported as:
[DllImport("TP9000.dll")]
public static extern int N_PrintJobStatus(int[] p1);
如果我在代码中不调用这个函数,它就不会挂起。但我应该如何管理它。文件说:

它检查打印的状态

int N_打印作业状态(int*pJobStatus) 参数pJobStatus[out]:

  • JobStatus[0]=优先级状态:空闲(0x00)、正在打印(0x01)、错误打印停止(0xFF)
  • JobStatus[1]=无备用作业(出错时,无暂停作业)
  • JobStatus[2]=备用作业数(包括当前正在运行的作业)
  • JobStatus[3]=当前运行作业的份数(打印份数的总数)
  • JobStatus[4]=剩余作业的副本数(剩余计数)
  • JobStatus[5]=是否显示重新打印检查窗口。1:自动选项显示,2:手动选项显示,0:无检查窗口
  • JobStatus[6]=检查错误处理和状态消息级别(1~4),然后在打印检查窗口(自动选项)显示0t

  • 打开打印机,然后检查功能区
  • 卡正在弹出
  • 正在同步功能区
  • 如果要重新打印,请按“确定”按钮。(激活“确定”按钮)
返回值0:成功-1:失败。(获取_状态)


好吧,如果没有剩下的代码,就不可能解决这个问题。错误代码如下所示:

int[] nJobSt = { 0, 0, 0, 0, 0, 0 }; //notice that the array length is 6
LastErrorCode = TP9000Dll.N_PrintJobStatus(nJobSt);
根据SDK文档,我们应该假设函数需要7的数组长度 因此,正确的代码是:

int[] nJobSt = { 0, 0, 0, 0, 0, 0, 0 }; //notice that the array length is 7
LastErrorCode = TP9000Dll.N_PrintJobStatus(nJobSt);

结论:阅读每个文档3次,永远不要相信SDK附带的示例应用程序。

这与问题的解决方案无关,但有时
BackgroundWorker
并不适合这项工作。另外:为什么要在应用程序中托管WCF服务,并从应用程序中调用它?如果都在同一个应用程序中,只需直接完成您的工作。这只是一个测试应用程序,在最终版本中没有backroundworker,客户端/服务器应用程序是两个独立的可执行文件。创建此应用程序是为了轻松重现问题(不幸成功)。