我正在使用 Gmap.net 库在谷歌地图上的三角测量算法进行计算后在特定的时间绘制标记,当我为两个标记工作时,它工作正常,但当我尝试绘制 5 个标记时,它向我显示异常
“System.InvalidOperationException”类型的未处理异常
发生在 mscorlib.dll 中
附加信息:集合已修改;枚举操作
可能不执行。
我正在做的事情是,我为五个标记创建了 5 个线程,这些标记绘制在地图上。
- 当标记正在绘制时,如果我进行大量放大缩小
它显示异常。
- 在绘制时,我再次移动地图,它显示异常。
i am unable to figure out why it is happening.even it is not showing me any line no. here is the snapshot of error.
please help.
EDIT: here is the code to plot on map includes adding markers and routes ,i have use same function for all 5 markers with different marker and routes name
void plot5(double temp_lat5, double temp_long5, string temp_date5, string temp_time5, string temp_bty_value5)
{
try
{
//GMapMarker marker5 = new GMarkerGoogle(new PointLatLng(temp_lat5, temp_long5), GMarkerGoogleType.lightblue);
GMapMarker marker5 = new GMarkerGoogle(new PointLatLng(temp_lat5, temp_long5), new Bitmap(Properties.Resources.image12));
gmap.Overlays.Add(markers5); // overlay added
Thread.Sleep(100);
markers5.Markers.Add(marker5); //marker added
marker5.ToolTipText = "AT CARD 05" + "\n" + "HIGH PRIORITY" + "\n" + temp_date5 + "\n" + temp_time5 + "\n" + temp_bty_value5 + "%"; //text to be displayed on the marker
// text properties
marker5.ToolTip.Fill = Brushes.Bisque;
marker5.ToolTip.Foreground = Brushes.White;
marker5.ToolTip.Stroke = Pens.Black;
marker5.ToolTip.TextPadding = new Size(20, 20);
if (count5 != 0)
{
List<PointLatLng> points5 = new List<PointLatLng>();
points5.Add(new PointLatLng(temp_lat5, temp_long5));
points5.Add(new PointLatLng(lat5, long5));
GMapRoute route5 = new GMapRoute(points5, "walk05");
route5.Stroke = new Pen(Color.Aquamarine, 3);
gmap.Overlays.Add(routes5); // first overlays then routes or markers
routes5.Routes.Add(route5);
}
count5++;
lat5 = temp_lat5;
long5 = temp_long5;
}
catch (Exception hy)
{ MessageBox.Show(hy.ToString()); }
这就是我调用不同线程/任务的方式(两者都尝试过)
private void button1_Click(object sender, EventArgs e)// Creating and startting threads for 5 diffrent at cards
{
try
{
if (m_parentform.update_flag_data == 1)
{
if (list_at.Count != 0)
{
for (int y = 0; y < list_at.Count; y++)
{
for (int x = 0; x < m_parentform.at_cards_serials.Count; x++)
{
if (list_at[y] == m_parentform.at_cards_serials[x])
{
try
{
int index = m_parentform.at_cards_serials.IndexOf(m_parentform.at_cards_serials[x]);
switch (index)
{
case 0:
{
Task lat_longthread1 = new Task(new System.Action(custom01));
lat_longthread1.Start();
// await lat_longthread1;
// Thread lat_longthread1 = new Thread(new ThreadStart(custom01));
// lat_longthread1.Start();
break;
}
case 1:
{
Task lat_longthread2 = new Task(new System.Action(custom02));
lat_longthread2.Start();
// await lat_longthread2;
//Thread lat_longthread2 = new Thread(new ThreadStart(custom02));
//lat_longthread2.Start();
break;
}
case 2:
{
Task lat_longthread3 = new Task(new System.Action(custom03));
lat_longthread3.Start();
// await lat_longthread3;
//Thread lat_longthread3 = new Thread(new ThreadStart(custom03));
//lat_longthread3.Start();
break;
}
case 3:
{
Task lat_longthread4 = new Task(new System.Action(custom04));
lat_longthread4.Start();
// await lat_longthread4;
//Thread lat_longthread4 = new Thread(new ThreadStart(custom04));
//lat_longthread4.Start();
break;
}
case 4:
{
Task lat_longthread5 = new Task(new System.Action(custom05));
lat_longthread5.Start();
// await lat_longthread5;
//Thread lat_longthread5 = new Thread(new ThreadStart(custom05));
//lat_longthread5.Start();
break;
}
}
}
catch (Exception ty)
{ MessageBox.Show(ty.ToString()); }
}
}
}
}
else
{ MessageBox.Show("select at cards to plot"); }
}
else
{ MessageBox.Show("flag is not updated"); }
}
catch (Exception jo)
{ MessageBox.Show(jo.ToString()); }
更改:以下是我所做的更改,添加了绘图功能(如上所述),对于关键部分中的所有 5 个标记,问题仍然相同。
void marker_selection(int plot_no)
{
mut2.WaitOne();
int marker_no = plot_no;
switch (marker_no)
{
case 1:
{
plot(one1, two1, date[0], time[0], bty[0]); // not sending bty part 2 which indicates milli volt value
break;
}
case 2:
{
plot2(one2, two2, date2[0], time2[0], bty2[0]); // sending only part one of bty
break;
}
case 3:
{
plot3(one3, two3, date3[0], time3[0], bty3[0]); // sending only part one of bty
break;
}
case 4:
{
plot4(one4, two4, date4[0], time4[0], bty4[0]); // sending only part one of bty
break;
}
case 5:
{
plot5(one5, two5, date5[0], time5[0], bty5[0]); // sending only part one of bty
break;
}
}
mut2.ReleaseMutex();
}