当用户点击按钮时,我想停止在main()中启动的调度程序.
private void button_start_Click(object sender, RoutedEventArgs e)
{
...
Camera.EventFrame -= onFrameEventFocusCam; //unsubscribe event
while (!Dispatcher.HasShutdownStarted)
{
// test if Dispatcher started shutdown --> ok, it does but never finishs...!
}
...
}
private void onFrameEventFocusCam(object sender, EventArgs e)
{
...
Dispatcher.Invoke(new Action(() =>
{
// Convert bitmap to WPF-Image
var bmp = new Bitmap(bitmap);
var hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
image_fokus.Source = wpfBitmap;
image_fokus.Stretch = System.Windows.Media.Stretch.UniformToFill;
DeleteObject(hBitmap);
bitmap.Dispose();
}));
GC.Collect();
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我在以下位置停止时收到以下错误消息onFrameEventFocusCam …
我有以下xml:
<Assembly>
<Bench>
<Typ>P1</Typ>
<DUT>
<A>6</A>
</DUT>
</Bench>
<Bench>
<Typ>P2</Typ>
<DUT>
<A>6</A>
</DUT>
</Bench>
</Assembly>
Run Code Online (Sandbox Code Playgroud)
如何获得可以插入新DUT的'P2'元素的引用?我尝试了以下代码,这给了我一个错误:
var xElement = xmlDoc.Element("Assembly")
.Elements("Bench")
.Where(item => item.Attribute("Typ").Value == "P2")
.FirstOrDefault();
xElement.AddAfterSelf(new XElement("DUT"));
Run Code Online (Sandbox Code Playgroud)
提前致谢