public void SendADThread(object obj) { List <ADItem> ADItem = (List <ADItem>)obj; SendData sendData = new SendData(); sendData.ActionCode = ActionCodeBase.PutInAdvertisement; List <ADFileStream> ADSL = new List <ADFileStream>(); foreach (ADItem item in ADItem) { FileInfo fi = new FileInfo(item.filePath); byte[] buff = new byte[fi.Length]; FileStream fs = fi.OpenRead(); fs.Read(buff, 0, Convert.ToInt32(fs.Length)); fs.Close(); ADFileStream ADS = new ADFileStream(); ADS.FileStream = buff; ADS.FileName = item.fileName_New; ADSL.Add(ADS); } byte[] bigData = ADSL.PaseToByte(); IntPtr[] ConnectionIDs = server.GetAllConnectionIDs(); bool result = false; foreach (IntPtr connId in ConnectionIDs) { server.SendBigDataToClient(connId, bigData, ActionCodeBase.PutInAdvertisement, null, null); } if (result) { MessageBox.Show("投放成功"); } else { MessageBox.Show("投放失败"); } }
/// <summary> /// 发布广告 /// </summary> /// <param name="ADItem"></param> private void SendAdvertisement(List <ADItem> ADItem) { //Thread SendBigDataThread = new Thread(SendADThread); //SendBigDataThread.Start(ADItem); new Thread(() => { try { //SendData sendData = new SendData(); //sendData.ActionCode = ActionCodeBase.PutInAdvertisement; List <ADFileStream> ADSL = new List <ADFileStream>(); foreach (ADItem item in ADItem) { FileInfo fi = new FileInfo(item.filePath); byte[] buff = new byte[fi.Length]; FileStream fs = fi.OpenRead(); fs.Read(buff, 0, Convert.ToInt32(fs.Length)); fs.Close(); ADFileStream ADS = new ADFileStream(); ADS.FileStream = buff; ADS.FileName = item.fileName_New; ADSL.Add(ADS); } byte[] bigData = ADSL.PaseToByte(); IntPtr[] ConnectionIDs = server.GetAllConnectionIDs(); foreach (IntPtr connId in ConnectionIDs) { server.SendBigDataToClient(connId, bigData, ActionCodeBase.PutInAdvertisement, null, null); } MessageBox.Show("投放成功"); } catch { MessageBox.Show("投放失败"); } }).Start(); }