c#代码中使用CMD和CommandLineTools时出现问题(尝试使用蓝牙) [英] problem in using CMD and CommandLineTools in c# code (try to use bluetooth)

查看:262
本文介绍了c#代码中使用CMD和CommandLineTools时出现问题(尝试使用蓝牙)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我正在编程一个项目,该项目将文件从计算机发送到手机.
我使用 BluetoothCLTools-1.2.0.51 程序来发现并发送我的文件. br/> 有我的代码:

hello.
I''m programming a project that sent a file from computer to phone.
I use BluetoothCLTools-1.2.0.51 programs to discovery and send my files.
There is my code:

Process p = new Process();
                ProcessStartInfo psi = new ProcessStartInfo("cmd","/c"+@"btobex -n"MyPhone" "C:\A.txt"");

                p.StartInfo = psi;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = false;
                p.StartInfo.ErrorDialog = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;

                p.Start();


当我直接使用Command Prom时没有问题,但是当我的电话询问是否允许接收文件时,如果我选择否",则通过我的代码启动Command Prom并将文件发送到电话中时,程序出现如下错误:


There is no problem when i use Command prom directly, but when start command prom by my code and sending file to phone if i select NO when my phone ask permission to receive file, the program has a error like this:

Problem Event Name=APPCRASH


当我使用


there is no error when i use

Run->CMD

推荐答案

时,没有错误,我不确定为什么会得到APPCRASH之类的信息,但是我的想法是,每当您需要实例化这样的过程时,明智的做法是将整个块包装在try catch中,以便在该第三方应用程序中发生任何无法预料的情况时,您可以至少在您的代码中妥善处理它.我不认为您还没有这样做,但是我认为值得一提以防万一.
如果使用try catch,则可以检查APPCRASH状态,并假定"用户选择了否.希望对您来说,不会有更多的情况会导致发生此特定错误.
I''m not sure about why you would get the APPCRASH and such, but my thought is that anytime you need to instantiate a process like this it would be wise for you to wrap the entire block in a try catch so that when anything unforseen happens in that 3rd party application you can at least deal with it gracefully in your code. I''m not assuming you haven''t done this, but I thought it worthwhile to mention just in case.
If you use the try catch you can check for the APPCRASH state and "assume" that the user has selected no. Hopefully for you there aren''t more situations that will cause this particular error to occur.


这篇关于c#代码中使用CMD和CommandLineTools时出现问题(尝试使用蓝牙)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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