English 中文(简体)
在叫拆台后停机坪
原标题:Program hangs after calling Dispose()

Im与C#共同开展一个项目。 该方案从一个连接的网络运动中获取图像,并通过Socket将其发送到Pi/iPad。 所有这些工作都很出色,我能够成功地看到我的行踪。

But when the client disconnects, the webcam has to get turned off and in this function, the program just hangs up. No error messages and no exception calls...just hangs! I believe it s a problem with multiple threads but unfortunately I m not as experienced in C# to find a solution. I hope someone here can bring me on the right track...

Code:
onImageCaptured function:

public void OnImageCaptured(Touchless.Vision.Contracts.IFrameSource frameSource, Touchless.Vision.Contracts.Frame frame, double fps)
{
    _latestFrame = frame.Image;
    Console.WriteLine("OnImageCaptured");
    if (isConnected)
    {
        Console.WriteLine("OnImageCaptured - isConnected");
        byteArray = new byte[0];
        MemoryStream stream = new MemoryStream();

        _latestFrame.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
        stream.Close();
        byteArray = stream.ToArray();

        if (byteArray.Length > 0)
        {
            string eof = "<EOF>";
            byte[] eofByte = Encoding.ASCII.GetBytes(eof);
            Console.WriteLine("OnImageCaptured - sendStream");
            this.onDataSend(byteArray);
            this.onDataSend(eofByte);
            stream.Flush();
        }

        System.Diagnostics.Debugger.Log(0, "1", "
Byte Array Length: " + byteArray.Length.ToString());
    }
    pictureBoxDisplay.Invalidate();
}

象照相机级一样:

public event EventHandler<CameraEventArgs> OnImageCaptured;

触发:

OnImageCaptured.Invoke(this, new CameraEventArgs(bitmap, fps));

因此,这一功能——我相信的话——面临一种单独的威胁,因为当图像出现时,不阻挡统一。

因此,在这一职能中处理客户脱节问题:

public void onDataSend(byte[] data)
{
    clientReady = false;
    try
    {
        socketWorker.Send(data);
    }
    catch (SocketException se)
    {
        isConnected = false;
        Console.WriteLine("Error: Data Write - SocketException");
        Console.WriteLine(se.ErrorCode.ToString());
        thrashOldCamera() // THIS FUNCTION HANGS THE PROGRAM !!
        onDisconnectServer();

        // onDisconnectServer();
    }
    catch (ObjectDisposedException)
    {
        isConnected = false;
        Console.WriteLine("Error: Data Write - ObjectDisposedException");
        // onDisconnectServer();
    }

}

用户脱节,thrashOldCamera()。 至今为止的工程罚款! 现在:

private void thrashOldCamera()
{
    Console.WriteLine("TrashOldCamera");
    // Trash the old camera
    if (_frameSource != null)
    {
        try
        {
            _frameSource.NewFrame -= OnImageCaptured;
            Console.WriteLine("TrashOldCamera - 1");
            _frameSource.Camera.Dispose(); // HERE IT HANGS. IT NEVER GOES PAST HERE !!!
            Console.WriteLine("TrashOldCamera - 2");
            setFrameSource(null);
            Console.WriteLine("TrashOldCamera - 3");
            pictureBoxDisplay.Paint -= new PaintEventHandler(drawLatestImage);
        }
        catch (Exception ex)
        {
            Console.WriteLine("End Trash Camera Ex: " + ex);
        }
    }
    Console.WriteLine("End Trash Camera");
}

The program hangs at _frameSource.Camera.Dispose();. As stated above, there s no error or exception. It may be a problem that onDataReceive() gets called within the onImageCapture function(). I also added a button to the form that triggers thrashOldCamera() and this works perfectly.

任何帮助/帮助都得到真正赞赏。

最佳回答

这被称为僵局,这是一个典型的可怕的问题。 我看不出你在座标的任何地方都明确援引“国际调查”,因此,僵局可能位于照相公司本身。 核心问题是,你在试图关闭“>,尽管“<>>>>”号照相机仍在执行之中,但是没有许多能够抗拒的密码。 释放(电离层)的电话可在回响完成之前完成。 但是,这种回击可以到(或)停电完毕为止。 致命的城市。

你们需要调整你们的法典,才能做到这一点。 推迟释放摄像机是关键,最好在打开照相机的同一天线上做。 比如,在形式上的闭门活动中,你也许会解决这个问题。 或根本不放电,将其留给Windows,自动关闭。

问题回答

Don t 知道这是否真的应该是一种评论或答案,但至少我可以走到正确的轨道上。

http://touchless.codeplex.com/SourceControl/changeset/view/55790“rel=“nofollow noreferer”> 深为。 这是<条码>。

public void Dispose()
{
    StopCapture();
}

.O.,没有获得任何帮助。 电话号码:

internal void StopCapture()
{
    _cameraMethods.StopCamera();
}

一次又一次无助于。 <代码>_cameraMethods> 摄像机/密码:来自图书馆的<密码>WebCamLib。 这是一个C++帮助图书馆,可以直接显示。

:StopCamera()。

void CameraMethods::StopCamera()
{
    if (g_pMediaControl != NULL)
    {
        g_pMediaControl->Stop();
        g_pMediaControl->Release();
        g_pMediaControl = NULL;
    }

    g_pfnCaptureCallback = NULL;

    if (g_pIBaseFilterNullRenderer != NULL)
    {
        g_pIBaseFilterNullRenderer->Release();
        g_pIBaseFilterNullRenderer = NULL;
    }

    if (g_pIBaseFilterSampleGrabber != NULL)
    {
        g_pIBaseFilterSampleGrabber->Release();
        g_pIBaseFilterSampleGrabber = NULL;
    }

    if (g_pIBaseFilterCam != NULL)
    {
        g_pIBaseFilterCam->Release();
        g_pIBaseFilterCam = NULL;
    }

    if (g_pGraphBuilder != NULL)
    {
        g_pGraphBuilder->Release();
        g_pGraphBuilder = NULL;
    }

    if (g_pCaptureGraphBuilder != NULL)
    {
        g_pCaptureGraphBuilder->Release();
        g_pCaptureGraphBuilder = NULL;
    }

    this->activeCameraIndex = -1;
}

看来,你的例外是在本土管理边界时吃饭。 我不知道这将多少帮助你,但至少会让你开始研究。

能够进行不受管理的编码分解,看看你是否能够通过图书馆来源进入,看看实际问题在哪里。

“entergraph

如果在C++/C#Interop方面有更多经验的其他人想这样做,并做更多的工作来辩论这个问题,那么我就把这个社区变成了乌基。

在装置互不关联的情况下确定援引该事件。 撰写该守则,以取代那里的网络广告。

就如仍有问题,使用。 电话:RefreshCameraList , 以便与照相机脱节,你还可以添加。 Touchless.CurrentCamera.Dispose if ya so wish to. 您仍可能需要使无人驾驶的伪造编码得以脱胎。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...