110,566
社区成员
发帖
与我相关
我的任务
分享
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 System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using System.Management.Instrumentation;
using Microsoft.Win32;
using BaseClass;
using KINTMESH.FCMS.GetRemoteData;
using KINTMESH.FCMS.RemoteDataObject;
using KNITMESH.FCMS.ClientDC.GUI;
using System.Data.SqlClient;
using System.IO;
namespace 测试
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string txt_IP = string.Empty;
private string txt_Port = string.Empty;
private static IGetRemoteData M_getRemoteData;
private void Form1_Load(object sender, EventArgs e)
{
txt_IP = "192.168.1.104";//config.AppSettings.Settings["RemoteServerIP"].Value;
txt_Port = "8086";//config.AppSettings.Settings["Port"].Value;
tim_GetData.Interval = 1000;
tim_LinkRemoteServer.Interval = 30000;
TcpChannel tcpChannel = new TcpChannel();
ChannelServices.RegisterChannel(tcpChannel, false);
LinkRemoteServer();
}
private void GetRemoteData()
{
InsertCommunicationToDB insert = new InsertCommunicationToDB(M_getRemoteData);
InsertCommunicationToDB.IsWritingCommunicationData = true;
insert.LoadCommunicationData();
InsertCommunicationToDB.IsWritingCommunicationData = false;
}
public void GetData_LinkError(Exception ex)
{
tim_LinkRemoteServer.Enabled = false;
tim_GetData.Enabled = false;
}
private void tim_GetData_Tick(object sender, EventArgs e)
{
if (!InsertCommunicationToDB.IsWritingCommunicationData)
{
GetRemoteData();
}
}
private void tim_LinkRemoteServer_Tick(object sender, EventArgs e)
{
if (LinkRemoteServer())
{
tim_GetData.Enabled = true;
}
}
private bool LinkRemoteServer()
{
string remotingConn = txt_IP + ":" + txt_Port;
bool testLink = false;
try
{
//lbl_LinkState.Text = "正在连接";
M_getRemoteData = (IGetRemoteData)Activator.GetObject(typeof(IGetRemoteData), "tcp://" + remotingConn + "/GetRemoteData");
testLink = M_getRemoteData.IsLink();
tim_GetData.Enabled = true;
//lbl_LinkState.Text = testLink ? "成功连接远程服务器" : "连接失败,尚未连接服务器";
tim_LinkRemoteServer.Enabled = false;
}
catch (System.Exception ex)
{
GetData_LinkError(ex);
//lbl_LinkState.Text = "连接失败,30秒后将重新连接服务器";
}
return testLink;
}
}
}