在一个类中通过事件委托的方法将该类中得到的信息委托出去执行,但委托出去的事件在调用中不能使用窗体中的控件信息,什么原因呀!!!!
清风树下 2007-11-26 04:02:51 我做一个TCP客户端连接的类,将该类中接收到的一个数据通过委托事件的方法委托出去由用户定义,可是在调用时定义委托的事件可以,但不能使用窗体中的控件等信息一使用就报错。该如何做呀!!!
这是一些基本定义信息:
#region 注册信息
/// <summary>
/// Sockets连接基本信息格式
/// </summary>
public class TchSocketsInfo
{
#region 连接信息
/// <summary>
/// SocketID
/// </summary>
private string ClientID = System.Guid.NewGuid().ToString(); //Socket连接ID
/// <summary>
/// 获取/设置Socket连接ID
/// </summary>
public string SetClientID
{
get { return this.ClientID; }
set { this.ClientID = value; }
}
/// <summary>
/// Socket名称
/// </summary>
private string ClientName = System.Guid.NewGuid().ToString(); // Socket名称
/// <summary>
/// 获取/设置Socket连接名称
/// </summary>
public string SetClientName
{
get { return this.ClientName; }
set { this.ClientName = value; }
}
/// <summary>
/// Socket连接类型(TCP\UDP\Client\Port)
/// </summary>
private string ClientType = "TCP";
/// <summary>
/// 获取/设置Socket连接类型(TCP\UDP\Client\Port)
/// </summary>
public string SetClientType
{
get { return this.ClientType; }
set { this.ClientType = value; }
}
/// <summary>
/// 连接Socket
/// </summary>
private Socket ClientSocket = null; //连接Socket
/// <summary>
/// 获取/设置连接Socket
/// </summary>
public Socket SetClientSocket
{
get { return this.ClientSocket; }
set { this.ClientSocket = value; }
}
/// <summary>
/// 指示连接是否成功
/// </summary>
private bool Bool_True = false;
/// <summary>
/// 获取/设置连接是否成功,为True是表示连接成功
/// </summary>
public bool SetBool_True
{
get { return this.Bool_True; }
set { this.Bool_True = value; }
}
/// <summary>
/// 记录该连接的连接时间
/// </summary>
private DateTime ClientConnect = DateTime.Now;
/// <summary>
/// 获取/设置连接的时间
/// </summary>
public DateTime SetClientConnect
{
get { return this.ClientConnect; }
set { this.ClientConnect = value; }
}
/// <summary>
/// 记录最后一次接收数据的时间
/// </summary>
private DateTime ClientDTConnect = DateTime.Now;
/// <summary>
/// 获取/设置最后一次接收数据的时间
/// </summary>
public DateTime SetClientDTConnect
{
get { return this.ClientDTConnect; }
set { this.ClientDTConnect = value; }
}
/// <summary>
/// 连接失效时间 单位:分钟
/// </summary>
private int Int_FailureTime = 1;
/// <summary>
/// 获取/设置连接失效时间(1) 单位:分钟
/// </summary>
public int SetFailureTime
{
get { return this.Int_FailureTime; }
set { this.Int_FailureTime = value; }
}
#endregion
#region 异步接收数据
/// <summary>
/// 异步接收数据存放的变量
/// </summary>
private byte[] ClientrecByte = null;
/// <summary>
/// 获取/设置异步接收数据存放的变量
/// </summary>
public byte[] SetClientrecByte
{
get { return this.ClientrecByte; }
set { this.ClientrecByte = value; }
}
/// <summary>
/// 异步接收数据时一次接收数据的大小
/// </summary>
private int Int_ByteSize = 1024;
/// <summary>
/// 获取/设置异步接收数据时一次接收数据的大小(1024) 单位:字节
/// </summary>
public int SetByteSize
{
get { return this.Int_ByteSize; }
set
{
this.Int_ByteSize = value;
this.ClientrecByte = new byte[value];
}
}
#endregion
#region 初次握手发送信息
/// <summary>
/// 是否发送握手信息
/// </summary>
private bool Bool_Shake = false;
/// <summary>
/// 获取/设置是否发送握手信息
/// </summary>
public bool SetBool_Shake
{
get { return this.Bool_Shake; }
set { this.Bool_Shake = value; }
}
/// <summary>
/// 是否发送握手信息还是ID信息,为True是表示握手信息
/// </summary>
private bool Bool_ShakeCode = true;
/// <summary>
/// 获取/设置是否发送握手信息还是ID信息,为True是表示握手信息
/// </summary>
public bool SetBool_ShakeCode
{
get { return this.Bool_ShakeCode; }
set { this.Bool_ShakeCode = value; }
}
/// <summary>
/// 初次握手发送信息
/// </summary>
private string Str_Txt = "Technic";
/// <summary>
/// 获取/设置初次握手发送信息
/// </summary>
public string SetStrTxt
{
get { return this.Str_Txt; }
set { this.Str_Txt = value; }
}
/// <summary>
/// 发送握手信息延迟时间 单位:毫秒
/// </summary>
private int Int_Interval = 0;
/// <summary>
/// 获取/设置发送握手信息延迟时间 单位:毫秒
/// </summary>
public int SetIntInterval
{
get { return this.Int_Interval; }
set { this.Int_Interval = value; }
}
#endregion
#region 心跳信息
/// <summary>
/// 心跳标识 是否启动心跳
/// </summary>
private bool Bool_HeartBit = false;
/// <summary>
/// 获取/设置心跳标识 是否启动心跳
/// </summary>
public bool SetBoolHeartBit
{
get { return this.Bool_HeartBit; }
set { this.Bool_HeartBit = value; }
}
/// <summary>
/// 心跳字符
/// </summary>
private string Str_HeartStr = "@";
/// <summary>
/// 获取/设置心跳字符
/// </summary>
public string SetStrHeartStr
{
get { return this.Str_HeartStr; }
set { this.Str_HeartStr = value; }
}
/// <summary>
/// 心跳间隔时间 单位:秒
/// </summary>
private int Int_HeartTime = 60;
/// <summary>
/// 获取/设置心跳间隔时间 单位:秒
/// </summary>
public int SetIntHeartTime
{
get { return this.Int_HeartTime; }
set { this.Int_HeartTime = value; }
}
/// <summary>
/// 接收心跳字符发送心跳,为空时表示心跳跳动正常
/// </summary>
private string Str_HeartShowStr = "";
/// <summary>
/// 获取/设置接收心跳字符,为空时表示心跳跳动正常
/// </summary>
public string SetSStrHeartShowStr
{
get { return this.Str_HeartShowStr; }
set { this.Str_HeartShowStr = value; }
}
#endregion
/// <summary>
/// 实时监控连接的状态/心跳启动
/// </summary>
public System.Timers.Timer ClientRecentTimer = new System.Timers.Timer();
/// <summary>
/// Socket接收数据状态标识
/// </summary>
public bool ClientIsReg = false;
/// <summary>
/// Object对象
/// </summary>
public object ClientObject = null;
}
#endregion