如何调试'System :: Threading :: ThreadStart'错误?

时间:2013-07-03 06:48:02

标签: .net multithreading visual-studio-2010 visual-c++ c++-cli

我最近使用的是MS Visual Studio 2010专业版,正在使用C ++ / CLI(Visual C ++)项目。我有一个名为SRecognizer的类,它使用一些C#库。现在,它有以下代码

r = gcnew RTMotionDetector();

Thread ^detectionThread = gcnew Thread(gcnew System::Threading::ThreadStart(this,&r->start()));

RMotionDetector类标题位于

之下
#pragma once
#include "MotionDetector.h"

ref class RTMotionDetector :
    public MotionDetector
{
public:
    RTMotionDetector(void);
    ~RTMotionDetector(void);
    void start();
    void pause();
    void stop();

private:
    VideoCapture *cam1;
};

程序运行时,会出现以下错误

1>------ Build started: Project: Automated Intruder Tracking System, Configuration: Debug Win32 ------
1>Build started 7/3/2013 1:03:49 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\Automated Intruder Tracking System.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1>  All outputs are up-to-date.
1>  SRecognizer.cpp
1>SRecognizer.cpp(38): error C2102: '&' requires l-value
1>SRecognizer.cpp(38): error C3350: 'System::Threading::ThreadStart' : a delegate constructor expects 2 argument(s)
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.19
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

正如您所看到的,错误在于我如何在SRecognizer中创建了您已经具有上述特定代码的线程。我是C ++ / CLI的新手。

1 个答案:

答案 0 :(得分:1)

这应该可以解决编译错误:

Thread^ detectionThread = gcnew Thread(gcnew System::Threading::ThreadStart(r, &RTMotionDetector::start));