private void ThrowMessage(MessageBody message) { if (UpdateMessage != null) { foreach (UpdateMessageHander t in UpdateMessage.GetInvocationList()) { t.BeginInvoke(message, null, null); } } }
/// <summary> /// //将Byte转换为结构体类型 /// </summary> /// <param name="bytes"></param> /// <param name="type"></param> /// <returns></returns> //public static object ByteToStruct(byte[] bytes,ref int indX,ref int indY) //{ // //List<Entity.DefectBlob> listBlob = new List<Entity.DefectBlob>(); // int size = Marshal.SizeOf(new Entity.DefectBlob()); // if (size > bytes.Length) // { // return null; // } // //get count // byte[] btCnt = new byte[4]; // //die index; // Array.Copy(bytes,btCnt,4); // indX = System.BitConverter.ToInt32(btCnt, 0); // //die indxe y // Array.Copy(bytes, 4, btCnt,0, 4); // indY = System.BitConverter.ToInt32(btCnt, 0); // //defect cout // Array.Copy(bytes,8, btCnt,0,4); // int defectCount = System.BitConverter.ToInt32(btCnt,0); // IntPtr structPtr = Marshal.AllocHGlobal(size); // int offset = 12; // for (int i=0;i<defectCount;i++) // { // Marshal.Copy(bytes, offset + i * size, structPtr, size); // var blob = Marshal.PtrToStructure(structPtr, typeof(Entity.DefectBlob)); // //listBlob.Add((Entity.DefectBlob)blob); // } // Marshal.FreeHGlobal(structPtr); // ////分配结构体内存空间 // //IntPtr structPtr = Marshal.AllocHGlobal(size); // ////将byte数组拷贝到分配好的内存空间 // //Marshal.Copy(bytes, 0, structPtr, size); // ////将内存空间转换为目标结构体 // //object obj = Marshal.PtrToStructure(structPtr, typeof(Entity.DefectBlob)); // ////释放内存空间 // //Marshal.FreeHGlobal(structPtr); // return listBlob; //} #endregion #region evt private void ThrowMessage(object msg) { if (UpdateMessage != null) { foreach (UpdateMessageHander t in UpdateMessage.GetInvocationList()) { t.BeginInvoke(msg, null, null); } } }