Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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+中处理停止或退出事件+/cli控制台应用程序_C++_.net_Multithreading_Event Handling_C++ Cli - Fatal编程技术网

C++ 在c+中处理停止或退出事件+/cli控制台应用程序

C++ 在c+中处理停止或退出事件+/cli控制台应用程序,c++,.net,multithreading,event-handling,c++-cli,C++,.net,Multithreading,Event Handling,C++ Cli,在一个控制台应用程序中,我使用TCP/IP连接连接到扫描设备,在连接建立后,我不断获取扫描测量值。但我需要用户在任何时候停止测量 我想在控制台应用程序中完成它。我需要使用线程吗?。如果用户在扫描过程中停止,我想完成特定的扫描和退出(像锁一样)。我只是学习C++和C++。任何建议都会有帮助。。谢谢 if (sopas.GetScanData(soScan) == true) { printf("Continuous Scanning Measurement \n"); processcoun

在一个控制台应用程序中,我使用TCP/IP连接连接到扫描设备,在连接建立后,我不断获取扫描测量值。但我需要用户在任何时候停止测量

我想在控制台应用程序中完成它。我需要使用线程吗?。如果用户在扫描过程中停止,我想完成特定的扫描和退出(像锁一样)。我只是学习C++和C++。任何建议都会有帮助。。谢谢

if (sopas.GetScanData(soScan) == true)
 {
 printf("Continuous Scanning Measurement \n");
 processcounter = ProcessScan(soScan,processcounter,gp,Background);
 }
流程扫描的这个框架是

unsigned int ProcessScan(const SLms100Scan& soScan,int iProcessedScanCount,FILE* gp,vector <double> &Background)
{
        static unsigned int ulDeg90_index = 0; // Calculated during init phase
    static unsigned int ulProcessedScanCounter = 0;
    int iDataCount = soScan.aDataChannel16.aFlexArrayData[0].aData.uiFlexArrayLength;

    int datalength = soScan.aDataChannel16.aFlexArrayData[0].aData.uiFlexArrayLength;
    vector <double> afXvalue(datalength);
    vector <double> afYvalue(datalength);

    pair<double,double> coord(int a,int b);
    vector< pair<double,double>> coordinates;

    int aiDataReal[80];
    int count;

    //Finding the blobs

    // Write hex values of data in to the file
    int success = 0;
    writefile(fname,soScan,success);
    if (success != 0)
        {
        printf("Error in printing the file");
        }

    blobdetector(soScan, iProcessedScanCount,Background,coordinates);
    // Read the hex value for XY co-ordinate calculation
    //readfile(fname,aiDataReal,idx,success);

    if (success == -1)
        printf("Error in reading the file");

    //calculation of Polar Coardinates to XY values
    findXY(soScan,afXvalue,afYvalue);

    //writing the XY values to the file
    writefile( wfname_XY,iDataCount,afXvalue,afYvalue,success);
    if (success == -1)
        printf("Error in printing the file");

    plotdata(afXvalue,afYvalue,coordinates,gp,iProcessedScanCount);

    if (!coordinates.empty())
        {
        //sendcoordinates(soScan,coordinates);
        writefile( "coordinates",soScan,coordinates);
        coordinates.clear();
        }

    iProcessedScanCount++;
    return iProcessedScanCount;
}
unsigned int ProcessScan(常量SLms100Scan&soScan,int-iProcessedScanCount,文件*gp,向量和背景)
{
静态无符号int-ulDeg90_index=0;//在初始化阶段计算
静态无符号整数ulProcessedScanCounter=0;
int iDataCount=soScan.aDataChannel16.aFlexArrayData[0].aData.uiFlexArrayLength;
int datalength=soScan.aDataChannel16.aFlexArrayData[0].aData.uiFlexArrayLength;
矢量afXvalue(数据长度);
向量afYvalue(数据长度);
配对坐标(内部a、内部b);
向量坐标;
国际援助组织[80];
整数计数;
//寻找斑点
//将数据的十六进制值写入文件
int成功=0;
writefile(fname、soScan、success);
如果(成功!=0)
{
printf(“打印文件时出错”);
}
blobdetector(soScan、iProcessedScanCount、背景、坐标);
//读取XY坐标计算的十六进制值
//readfile(fname、aiDataReal、idx、success);
如果(成功==-1)
printf(“读取文件时出错”);
//极坐标与XY值的计算
findXY(soScan、afXvalue、afYvalue);
//将XY值写入文件
writefile(wfname_XY、iDataCount、afXvalue、afYvalue、success);
如果(成功==-1)
printf(“打印文件时出错”);
绘图数据(afXvalue、afYvalue、坐标、gp、I处理扫描计数);
如果(!coordinates.empty())
{
//发送坐标(soScan,坐标);
writefile(“坐标”,soScan,坐标);
坐标。清除();
}
i处理扫描计数++;
返回iProcessedScanCount;
}
一种简单的方法(在windows上)是使用并阻止终止,直到您完成工作,当然,如果发生
CTRL\u CLOSE\u事件,您在Win7/Vista上的时间有限


您可以使用不同的机制向主程序发送信号,以完成其工作。在我的例子中,我在主文件中使用了一个全局变量,通过引用将其传递给我的内部循环,并将其用作循环终止条件。但是它也可以通过其他方法实现(
条件变量
,…)

你能给我举个例子吗..请。。我在这里给出的processscan函数中有很多函数。我不知道如何停止中间的数据处理并再次恢复,直到用户发出停止命令时整个过程扫描功能完成。如果您在
PocessScan
中有一个主循环,您可以检查该循环的终止条件,如果它更复杂,您应该在更多地方检查该条件。如果您对该做什么感到困惑,那么最好发布
ProcessScan
方法的框架,我会尽力帮助您。