如何将文件从一个EXE传输到其他EXE [英] How to Transfer files from one EXE to Other EXE

查看:143
本文介绍了如何将文件从一个EXE传输到其他EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个EXE说EXE1和EXE2 ..



我正在使用EXE1编写文本文件。

一旦EXE1写一个应该向EXE2发送确认的文件。

这样EXE2可以读取该文件。



如何使用TCP或任何其他IPC。



主要的事情是EXE2不应该使用大部分CPU。

因为我在EXE2中尝试了以下

I am having two EXE's say EXE1 and EXE2..

I am writing a textfile using EXE1.
As soon as EXE1 writes a file it should send an acknowledgement to EXE2.
So that EXE2 can read that file.

How to do this using TCP or any other IPC.

The main Thing is that EXE2 should not use most of the CPU.
Because I tried the below in EXE2

while(true)
{

    if(File.Exists(Path)
        {
        }
}







几乎使用99%的CPU使用率。

如何摆脱这个。

任何人都可以帮我解决代码。




It almost use 99 Percentage of CPU Usage.
How to get rid of this.
Can anyone help me with code.

推荐答案

你应该使用基于 NetTcpBinding ( net.tcp 或其他绑定)和for do你应该这样:



1.你的EXE2应该是WCF服务器(公开WCF服务以供其他应用程序使用);



2.你EXE!应该是WCF客户端。



3.这里有一些文章可以作为WCF的起点使用:

Windows Communication Foundation Basics [ ^ ]

WCF for Beginners [ ^ ]

Windows Communication Foundation快速入门 - 多个绑定VS2010 [ ^ ]
You should use WCF (Windows Communication Foundation) based on NetTcpBinding (net.tcp or other binding) and for doing this you should:

1.You EXE2 should be the WCF server (that expose a WCF service to be used by others applications);

2.You EXE! should be the WCF client.

3.Here are some articles that could be used by you as WCF starting points:
Windows Communication Foundation Basics[^]
WCF for Beginners[^]
Windows Communication Foundation QuickStart - Multiple Binding VS2010[^]


为了减少CPU使用率,你需要把你的线程要睡觉。

否则它会在你的while循环中不断循环阻止。



喜欢这个。

To reduce CPU usage you need to put your thread to sleep.
Or else it will block by constantly loop in your while loop.

like this.
//Add "using System.Threading;"
while(true)
{
    if(File.Exists(Path))
        {
        }
Thread.Sleep(1);
}





对于TCP通信,您需要服务器和客户端(或多个客户端)。

查看 TcpListener [ ^ ]服务器和 TcpClient [ ^ ]。祝你好运。



For TCP communication you need a server and a client (or multiple clients).
Take a look atTcpListener[^] for server and TcpClient[^] for clients. Good luck.


这篇关于如何将文件从一个EXE传输到其他EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆