Thread tv = null;
private void UCGIS_Load(object sender, EventArgs e)
{
try
{
tv = new Thread(new ThreadStart(DoWork));
tv.IsBackground = true;
tv.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void DoWork()
{
WaitCallback wc = new WaitCallback(this.DoSomething);
ThreadPool.QueueUserWorkItem(wc);
}
private delegate void MyInvokeDelegate();
//线程要调用的函数
private void DoSomething(object o)
{
this.Invoke(new MyInvokeDelegate(this.LoadMap));
}
private void LoadMap()
{
try
{
IAGSServerConnectionFactory connectionFactory = new AGSServerConnectionFactory();
IPropertySet propertySet = new PropertySet();
IAGSServerConnection connection = null;
propertySet.SetProperty("url", "http://110.000.000.000:8081/ArcGIS/services");
connection = connectionFactory.Open(propertySet, 0);
//获取MapService对象
IAGSEnumServerObjectName serverObjectNames;
IAGSServerObjectName serverObjectName;
serverObjectNames = connection.ServerObjectNames;
while ((serverObjectName = serverObjectNames.Next()) != null)
{
if (serverObjectName.Name.Equals("basemap1") && serverObjectName.Type.Equals("MapServer"))
break;
}
if (serverObjectName == null)
{
WaitForm.Close();
MessageBox.Show("无法连接远程地图数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
IName name = serverObjectName as IName;
IMapServer mapServer = name.Open() as IMapServer;
IMapServerLayer layer = new MapServerLayer() as IMapServerLayer;
layer.ServerConnect(serverObjectName, mapServer.DefaultMapName);
axMapControl1.AddLayer(layer as ILayer);
axMapControl1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
WaitForm.Close();
}
}