我希望能够通过另一个类更新我的UI界面。我已经尝试通过创建一个form1对象并使用方法来更新文本框来实现此操作。但是这会导致一个错误,告诉我我的设备未正确运行。
所以基本上我如何在我的samplegrabber.cs类中使用我的Form1更新文本框?这个类被不断地调用,但是我只需要使用字符串。
ISampleGrabber类调用SampleCB方法,该方法包括:
public int SampleCB(double sampletime, IMediaSample sample)
{
if (sample == null)
{
return -1;
}
try
{
int length = sample.GetActualDataLength();
IntPtr buffer;
if (sample.GetPointer(out buffer) == 0 && length > 0)
{
Bitmap bitmapOfFrame = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, buffer);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Marshal.ReleaseComObject(sample);
return 0;
}
在if语句中创建了form1对象,即使我创建该对象(甚至没有f1.updateTextBox(id);
)也会出现错误。
`updateTextBox1'是在Form1中创建的:
public void updateTextBox1(string id)
{
textBox1.Text = id;
}
我收到的错误如下:
COMException(0x8007001F) - 系统附加的设备未正常工作。