REMOTING IpcChannel 问题

gctren 2008-07-16 03:50:48
我有个程序, 先注册了一个IpcChannel serverChannel = new IpcChannel("localhost");

如下场景:
一个程序,起了一个实例后,我会再起个实例,对原先那个实例KILL掉, 再运行新起的实例。
那样的话,我再次运行IpcChannel serverChannel = new IpcChannel("localhost"); 先报“创建 IPC 端口失败: 拒绝访问。”
我试过:

IChannel[] channels = ChannelServices.RegisteredChannels;
foreach (IChannel channel in channels)
{
IpcChannel ipc = channel as IpcChannel;
if (ipc == null)
{
continue;
}
ipc.StopListening(null);
ChannelServices.UnregisterChannel(ipc);
ipc = null;
}
也未能有用, 请教下是我要如何解决。
...全文
257 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bonntom 2009-03-06
  • 打赏
  • 举报
回复
ChannelServices的RegisteredChannels只会针对本AppDomain的,你不能直接从自己的AppDomain去关闭别的AppDomain的IpcChannel的,只能让它自己关闭自己啦
bonntom 2009-03-06
  • 打赏
  • 举报
回复
使用IpcChannel的StopListening方法即可。。。。
atlasroben 2008-07-16
  • 打赏
  • 举报
回复
http://topic.csdn.net/t/20050201/09/3767433.html
你看这个是否你能用
gctren 2008-07-16
  • 打赏
  • 举报
回复
如何关闭端口啊? 能否给个代码提示下。
atlasroben 2008-07-16
  • 打赏
  • 举报
回复
我粗略找了一下没有找到这方面的方法,你仅能够在异常捕获的时候关闭对这个端口的占用来加快系统对端口的释放,同时你也仅能通过try来判断端口是否被占用
gctren 2008-07-16
  • 打赏
  • 举报
回复
嗯。 是被占用着。 但我如何能够把他及时的释放掉呢。
atlasroben 2008-07-16
  • 打赏
  • 举报
回复
因为你第二次调用的时候注册那个端口被第一次的注册所占用,还没有释放
kbryant 2008-07-16
  • 打赏
  • 举报
回复
up

110,032

社区成员

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

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

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