private void QuerySurroundStationFromStationDB(PlaceFreqPlan[] freqs) { StationItemsSource.Clear(); ActivityStationItemsSource.Clear(); this.busyIndicator.IsBusy = true; EventWaitHandle[] waitHandles = new EventWaitHandle[freqs.Length]; for (int i = 0; i < freqs.Length; i++) { waitHandles[i] = new AutoResetEvent(false); } System.Threading.SynchronizationContext syccontext = System.Threading.SynchronizationContext.Current; Action <PlaceFreqPlan[], EventWaitHandle[]> action = new Action <PlaceFreqPlan[], EventWaitHandle[]>(this.QuerySurroundStation); action.BeginInvoke(freqs, waitHandles, obj => { WaitHandle.WaitAll(waitHandles); syccontext.Send(objs => { this.busyIndicator.IsBusy = false; CreateSurroundStation(StationItemsSource); if (ActivityStationItemsSource.Count > 0) { SurroundStationSelectorDialog stationdialog = new SurroundStationSelectorDialog(ActivityStationItemsSource); stationdialog.SaveCallbcak += (result) => { if (result) { this.Close(); if (RefreshItemsSource != null) { RefreshItemsSource(); } } }; stationdialog.ShowDialog(); } else { MessageBox.Show("未查询到周围台站,请重新选择查询条件"); } }, null); }, null); }
/// <summary> /// 查询周围台站 /// </summary> private void QuerySurroundStation(PlaceFreqPlan[] freqs, EventWaitHandle[] waitHandles) { List <StationInfo> surroundstation = new List <StationInfo>(); for (int i = 0; i < freqs.Length; i++) { PlaceFreqPlan freqplan = freqs[i]; string freqRange = (freqplan.MHzFreqFrom).ToString() + ";" + (freqplan.MHzFreqTo).ToString(); #region 真实参数 Point[] points = new Point[freqplan.RangePointList.Count]; for (int p = 0; p < freqplan.RangePointList.Count; p++) { GeoPoint point = freqplan.RangePointList[p]; points[p] = new Point() { X = point.Longitude, Y = point.Latitude }; } Point leftTop = new Point() { X = freqplan.LongitudeRange.Little, Y = freqplan.LatitudeRange.Great }; Point RightBottom = new Point() { X = freqplan.LongitudeRange.Great, Y = freqplan.LatitudeRange.Little }; #endregion #region 测试数据 //Point[] points = new Point[5] //{ // new Point(){X=106,Y=36}, // new Point(){X=110,Y=36}, // new Point(){X=110,Y=30}, // new Point(){X=106,Y=30}, // new Point(){X=106,Y=36}, //}; //Point leftTop = new Point() //{ // X = 106, // Y = 36 //}; //Point RightBottom = new Point() //{ // X = 110, // Y = 30 //}; #endregion QueryStationData(points, leftTop, RightBottom, freqRange, waitHandles[i], stations => { lock (locked) { StationItemsSource.AddRange(stations); //ActivitySurroundStation activitystation = new ActivitySurroundStation(); //activitystation.ActivityId = this.CurrentActivityPlace.ActivityGuid; //activitystation.FreqPlan = freqplan; //activitystation.PlaceId = this.CurrentActivityPlace.Guid; //ActivityStationItemsSource.Add(activitystation); } }); } }