使用产品:SuperMap Objects 6 操作系统:win8 x64
数据类型: 文件型
问题详细描述:开始的5次左右加载正常,但是次数多就直接崩溃了,调试时出现最多的问题是(尝试读取或写入受保护的内存。内存已损坏。),现在不提示错误了,直接崩溃了
问题重现步骤: 1.不断勾选图层10次左右
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SuperMapLib;//添加引用
using System.Runtime.InteropServices;//添加引用
using System.Collections;//集合引用
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region 打开数据源文件
private void button1_Click_1(object sender, EventArgs e)
{
//打开按钮事件
//问题一,用户选定文件
//设置对话框
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "我是标题";
openFileDialog1.Filter = "sdd文件|*.sdd;*sdb;|所有文件|*.*";
openFileDialog1.InitialDirectory = Application.StartupPath;
//DialogResult dlgRuslut = openFileDialog1.ShowDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
//用户按的是打开按钮
//问题2,得到用户选定的文件全路径
//问题3,核心方法打开
//工作空间控件.opendatasource()-数据源对象sodatasource
//先关闭再打开
axSuperWorkspace1.Close();
string sourcefile = openFileDialog1.FileName;
textBox1.Text = sourcefile;
textBox1.ReadOnly = true;
list_item();
axSuperWorkspace1.Close();
}
}
#endregion
#region 在checklistbox中列出项目的方法
public void list_item()
{
checkedListBox1.Items.Clear();
axSuperWorkspace1.Close();
soDataSource soDatasource = axSuperWorkspace1.OpenDataSource(textBox1.Text, "sdd", seEngineType.sceSDBPlus, false);
if (soDatasource != null)
{
soDatasets soDatasets = soDatasource.Datasets;//数据集,集合对象
for (int i = 1; i <= soDatasets.Count; i++)
{
checkedListBox1.Items.Add(soDatasets[i].Name);//同理在复选框中列出数据集名称
}
}
else
{
MessageBox.Show("打开数据源失败!", "提示");
}
}
#endregion
#region 遍历加载选中的图层的方法
public void xuanzhong()
{
axSuperWorkspace1.Close();
axSuperMap2.Close();
axSuperMap2.Refresh();
ConnectSuperMap();
soDataSource soDatasource = axSuperWorkspace1.OpenDataSource(textBox1.Text, "sdd", seEngineType.sceSDBPlus, false);
soDatasets soDatasets = soDatasource.Datasets;//数据集,集合对象
soLayer oblayer2;
for (int i = 0; i < checkedListBox1.CheckedIndices.Count; i++)
{
int k = i + 1;
oblayer2 = axSuperMap2.Layers.AddDataset(soDatasets[k], false);
}
axSuperMap2.Refresh();
}
#endregion
#region 工作空间与地图连接,句柄连接的方法
private void ConnectSuperMap() //自定义函数,用来关联控件
{
//关联SuperMap控件
object objHandle = axSuperWorkspace1.ObjectHandle; //工作空间控件句柄
axSuperMap2.Connect(objHandle);
Marshal.ReleaseComObject(objHandle);
objHandle = null;
}
#endregion
#region 勾选事件
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
checkedListBox1.CheckOnClick = true;
xuanzhong();
}
#endregion
}
}
萌新尝试很多次了,望大神指导一下,万分感激!