windows服务进程问题

hhwangke 2009-11-19 11:32:25
我用C#写了个服务用来启动某个应用程序,该应用程序实现接收数据并插入数据库。启动服务后一切正常,我注消后,查看进程和服务发现服务正常启动,进程也存在,然后中传输数据,可是没有任何反应。而重新启动服务后就可以了。想问一下这是什么情况,难道注销后进程会停止运行。我的应用程序代码如下,希望知道的朋友告诉我一下该如何去做。应用程序中还有两个时钟

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;

}

}
}

...全文
117 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
laokaizzz 2009-11-19
  • 打赏
  • 举报
回复
友情帮顶,你分忒少了,加点分,肯定有高手来
hhwangke 2009-11-19
  • 打赏
  • 举报
回复
然后中传输数据 多出了一个字 应该是 然后传输数据
hhwangke 2009-11-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 red_stone 的回复:]
大段的代码啊,看着头疼...建议只把问题代码贴出来就行
[/Quote]
我只是在下面贴了点代码。问题在上面不是写了吗。
hhwangke 2009-11-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 l90218597 的回复:]
代码写的我都看不懂了,小弟对你的敬仰...
[/Quote]
这里面很多是直接调用的DLL里的方法。这些不用管。只是注销后为什么程序不起作用了。这点不明白啊。
Red_Stone 2009-11-19
  • 打赏
  • 举报
回复
大段的代码啊,看着头疼...建议只把问题代码贴出来就行
l90218597 2009-11-19
  • 打赏
  • 举报
回复
代码写的我都看不懂了,小弟对你的敬仰...

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧