static void AsyncExcute(int s) { ThreadManage.BindThreadResource(s); pool[s].threadid = GetCurrentThreadId(); try { while (true) { pool[s].are.WaitOne(); if (stop) { return; } pool[s].run = true; for (int i = s; i < buff_async.Length; i += 2) { if (buff_async[i] != null) { buff_async[i](); buff_async[i] = null; } } pool[s].run = false; } // ... throw null; // 异常会在下面被捕获 // ... } catch (Exception ex) { // 一般会记录异常, 和/或通知其它线程我们遇到问题了 // ... Debug.WriteLine(ex); } }
static void PointerOperation(object sender, PointerRoutedEventArgs e) { PointerPoint p = PointerPoint.GetCurrentPoint(e.Pointer.PointerId); DX_Input.CopyPointer(p); if ((sender as SwapChain).EventToSubThread) { ThreadManage.AsyncDelegate(() => { (sender as SwapChain).CheckEvent(); }); } else { (sender as SwapChain).CheckEvent(); } }
internal static D2D1.Factory GetD2DFactory() { object o = ThreadManage.QurayResource(Key_Class.D2dIFactory2); D2D1.Factory fac; if (o == null) { fac = new D2D1.Factory(); ThreadManage.AddResource(Key_Class.D2dIFactory2, fac); } else { fac = o as D2D1.Factory; } return(fac); }
internal static Wic.ImagingFactory2 GetWicFactory() { object o = ThreadManage.QurayResource(Key_Class.WicIFactory); Wic.ImagingFactory2 fac; if (o == null) { fac = new Wic.ImagingFactory2(); ThreadManage.AddResource(Key_Class.WicIFactory, fac); } else { fac = o as Wic.ImagingFactory2; } return(fac); }
public SwapChain(double width, double height) { Width = width; Height = height; com = new SwapChainComponent(); com.panel = this; com.dpi = DisplayInformation.GetForCurrentView().LogicalDpi; DX_Core.CreateD3DInstance(ref com); DX_Child = new List <UIElement>(); this.PointerPressed += PointerOperation; this.PointerMoved += PointerOperation; this.PointerReleased += PointerOperation; this.PointerEntered += PointerOperation; this.PointerExited += PointerOperation; this.PointerWheelChanged += PointerOperation; var bp = new D2D1.BitmapProperties1( new D2D1.PixelFormat(Dxgi.Format.B8G8R8A8_UNorm, D2D1.AlphaMode.Premultiplied), com.dpi, com.dpi, D2D1.BitmapOptions.Target); lock (DX_Core.D2D) BitmapBuffer = new D2D1.Bitmap1(DX_Core.D2D.d2dContext, new Size2((int)width, (int)height), bp); ThreadManage.StartLoop(this); }