110,538
社区成员
发帖
与我相关
我的任务
分享
int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
try
{
if (!mbGotOne)
{
// The buffer should be long enought
if (BufferLen <= mstride * mvideoHeight)
{
// Copy the frame to the buffer
// m_handle = pBuffer;
CopyMemory(mhandle, pBuffer, mstride * mvideoHeight);
// m_handle = pBuffer;
mbGotOne = true;//这里弹出错误。
// Picture is ready.
mpictureReady.Set();
}
}
else
{
mdropped++;
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
return 0;
}
public IntPtr GetBitMap()
{
try
{
mhandle = Marshal.AllocCoTaskMem(mstride * mvideoHeight);
mpictureReady.Reset();
mbGotOne = false;
// If the graph hasn't been started, start it.
Start();
if (!mpictureReady.WaitOne(50, false)) //引发System.AccessViolationException异常
{
// throw new Exception("Timeout waiting to get picture");
Marshal.FreeCoTaskMem(mhandle);
return IntPtr.Zero;
}
// createTxt("test", (timeGetTime() - starttime).ToString() + " 1 " + m_handle.ToString() + " " + (ptrFlag++).ToString());
}
catch
{
Marshal.FreeCoTaskMem(mhandle);
return IntPtr.Zero;
}
return mhandle;
}
这里面的WaitOne(50, false)把50调大就不会出异常了,不明所以。。[/quote]
我在msdn上看到的:
WaitHandle.WaitOne (Int32, Boolean) 说明:
在派生类中被重写时,阻塞当前线程,直到当前的 WaitHandle 收到信号,使用 32 位有符号整数度量时间间隔并指定是否在等待之前退出同步域。
由 .NET Compact Framework 支持。
[/quote]这个我也看到了,但我还是不明白原因、。。。[/quote]
我也不明白 public IntPtr GetBitMap()
{
try
{
mhandle = Marshal.AllocCoTaskMem(mstride * mvideoHeight);
mpictureReady.Reset();
mbGotOne = false;
// If the graph hasn't been started, start it.
Start();
if (!mpictureReady.WaitOne(50, false)) //引发System.AccessViolationException异常
{
// throw new Exception("Timeout waiting to get picture");
Marshal.FreeCoTaskMem(mhandle);
return IntPtr.Zero;
}
// createTxt("test", (timeGetTime() - starttime).ToString() + " 1 " + m_handle.ToString() + " " + (ptrFlag++).ToString());
}
catch
{
Marshal.FreeCoTaskMem(mhandle);
return IntPtr.Zero;
}
return mhandle;
}
这里面的WaitOne(50, false)把50调大就不会出异常了,不明所以。。[/quote]
我在msdn上看到的:
WaitHandle.WaitOne (Int32, Boolean) 说明:
在派生类中被重写时,阻塞当前线程,直到当前的 WaitHandle 收到信号,使用 32 位有符号整数度量时间间隔并指定是否在等待之前退出同步域。
由 .NET Compact Framework 支持。
[/quote]这个我也看到了,但我还是不明白原因、。。。 public IntPtr GetBitMap()
{
try
{
mhandle = Marshal.AllocCoTaskMem(mstride * mvideoHeight);
mpictureReady.Reset();
mbGotOne = false;
// If the graph hasn't been started, start it.
Start();
if (!mpictureReady.WaitOne(50, false)) //引发System.AccessViolationException异常
{
// throw new Exception("Timeout waiting to get picture");
Marshal.FreeCoTaskMem(mhandle);
return IntPtr.Zero;
}
// createTxt("test", (timeGetTime() - starttime).ToString() + " 1 " + m_handle.ToString() + " " + (ptrFlag++).ToString());
}
catch
{
Marshal.FreeCoTaskMem(mhandle);
return IntPtr.Zero;
}
return mhandle;
}
这里面的WaitOne(50, false)把50调大就不会出异常了,不明所以。。[/quote]
我在msdn上看到的:
WaitHandle.WaitOne (Int32, Boolean) 说明:
在派生类中被重写时,阻塞当前线程,直到当前的 WaitHandle 收到信号,使用 32 位有符号整数度量时间间隔并指定是否在等待之前退出同步域。
由 .NET Compact Framework 支持。
public IntPtr GetBitMap()
{
try
{
mhandle = Marshal.AllocCoTaskMem(mstride * mvideoHeight);
mpictureReady.Reset();
mbGotOne = false;
// If the graph hasn't been started, start it.
Start();
if (!mpictureReady.WaitOne(50, false)) //引发System.AccessViolationException异常
{
// throw new Exception("Timeout waiting to get picture");
Marshal.FreeCoTaskMem(mhandle);
return IntPtr.Zero;
}
// createTxt("test", (timeGetTime() - starttime).ToString() + " 1 " + m_handle.ToString() + " " + (ptrFlag++).ToString());
}
catch
{
Marshal.FreeCoTaskMem(mhandle);
return IntPtr.Zero;
}
return mhandle;
}
这里面的WaitOne(50, false)把50调大就不会出异常了,不明所以。。