如果拔下网线,Windows iot会停止UWP应用程序
问题描述:
我们使用Windows IoT通过TCPClient连接到网络中的另一个应用程序。现在所有的作品,除了使我们感到困惑的一点。当我们从我们的树莓派中拔出网线时(我猜是版本2),使用GUI的启动应用程序立即停止。当我们插入电缆后,一段时间后,启动应用程序再次启动。如果拔下网线,Windows iot会停止UWP应用程序
我们使用VS2017构建arm UWP应用程序。
任何想法如何防止停止应用程序?
答
由于没有您的源代码,我不确定是什么原因导致您的问题。我测试了以下片段代码在树莓派3,当我拔掉网线时,与UI的应用程序不停止。在前台任务,异步方法建议,请参考Asynchronous programming。
服务器:
TcpListener tcpListener = new TcpListener(IPAddress.Any, 6550);
tcpListener.Start();
byte[] buffer = new byte[1024];
String data = string.Empty;
while (true)
{
var client = await tcpListener.AcceptTcpClientAsync();
var stream = client.GetStream();
int i = 0;
// Loop to receive all the data sent by the client.
do
{
i = await stream.ReadAsync(buffer, 0, buffer.Length);
if(i > 0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(buffer, 0, i);
//Display received message
txtRServerContent.Text = data;
}
} while (i > 0);
}
客户:
TcpClient tcpClient = new TcpClient(AddressFamily.InterNetwork);
await tcpClient.ConnectAsync(IPAddress.Parse("10.168.197.66"), 14400);
// Get a client stream for reading and writing.
// Stream stream = client.GetStream();
NetworkStream stream = tcpClient.GetStream();
// Buffer to store the response bytes.
byte[] data = new byte[1024];
// String to store the response ASCII representation.
String responseData = String.Empty;
int count = 0;
while (true)
{
// Read the first batch of the TcpServer response bytes.
count = await stream.ReadAsync(data, 0, data.Length);
if (count > 0)
{
responseData = System.Text.Encoding.ASCII.GetString(data, 0, count);
//Dispaly responsed message
txtClientContent.Text = responseData;
}
}
+0
谢谢,我会看看我可以使用。只是一个问题。我相信也是一个未处理的异常可能是原因,但我已经为App分配了UnhandledException事件。一旦我看到我的msgbox,但没有拔掉网络电缆,但似乎我的文件记录器刷新,直到应用程序关闭。 – Trivalik
答
看来,如果附加调试器只出现此问题。目前这个主题已经关闭。
在Raspberry PI SE上可能会更好。 – jdv
“Raspberry PI SE”是什么意思?我不知道。它是Linux吗?如果是这样,它是没有选择的。 – Trivalik
https://raspberrypi.stackexchange.com/ – jdv