应用程序返回值的设置与获取
2010-07-29 16:40
99 查看
program 1 Code:
program 2 Code:
ProjectName:parameters.exe
下面的代码反映一种巧妙的返回值机制:
总结,为了忘却。
private void button1_Click(object sender, EventArgs e) { Process process = new Process(); process.StartInfo.FileName =Application.StartupPath +"//parameters.exe"; process.StartInfo.Arguments = this.textBox1.Text.Trim(); int isEx = -1; process.Start(); process.WaitForExit(); isEx = process.ExitCode; Trace.WriteLine("retruen: " + isEx); textBox2.Text = isEx.ToString(); }
program 2 Code:
ProjectName:parameters.exe
static int Main(string[] args) { if (args.Length > 0) { for (int i = 0; i < args.Length; i++) { Console.WriteLine("param: " + args[i].ToString()); } Console.ReadLine(); return 10; } else { Console.ReadLine(); return 5; } }
下面的代码反映一种巧妙的返回值机制:
static int Main(string[] args) { try { //--------------------------------------------------------------------- bool onlyInstance = false; // if you want your app to be limited to a single instance across ALL SESSIONS (multiple users & terminal services), then use the following line instead: string mutexName = String.Format("Global//{0}.{1}", applicationName, AssemblyGuidString); Mutex mutex = new Mutex(true, mutexName, out onlyInstance); if (!onlyInstance) { //For FindWindow to work, applicationName must be the same as the title (the Text property) of your MainForm. IntPtr hwndFirstInstance = WinHelper.FindWindow(null, applicationName); WinHelper.PostMessage(hwndFirstInstance, WinHelper.WM_SHOWFIRSTINSTANCE, IntPtr.Zero, IntPtr.Zero); return CommConst.MAINRETURN_USERALREADYLOGIN; } //------------------------------------------------------------------- Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); log4net.Config.XmlConfigurator.Configure(); //------------------------------------------------------------------- //cross the windows control,login failed, return msg if (args != null && args.Length == 4 && ??? && ???) { LoginForm loginForm = new LoginForm(args[1], args[3]); int rtn = loginForm.MainReturnMsg; if (rtn == CommConst.MAINRETURN_NAMEORPWDERROR || rtn == CommConst.MAINRETURN_NETEXCEPTION || rtn == CommConst.MAINRETURN_USERLOCKUP || rtn == CommConst.MAINRETURN_USERALREADYLOGIN) { return rtn; } } //---------------------------↓---------chenys //如果要通过代码运行进行调试,这里的几行代码请暂时注释掉,不然没有办法进行跟踪调试 if (args != null && args.Length == 0) { Process process = new Process(); process.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XXXClient.Update.exe"); process.Start(); return CommConst.MAINRETURN_UPDATING;// } //---------------------------↑--------- //------------------------------------------------------------------ if (args != null && args.Length == 0) { Application.Run(new XXXClientAppContext()); } else if (args != null && args.Length == 1) { Process[] processList = Process.GetProcessesByName("XXXClient.Update"); for (int i = 0; i < processList.Length; i++) { processList[i].Kill(); } Application.Run(new XXXClientAppContext()); } else if (args != null && args.Length == 4 && ??? && ???) { //登录验证成功:1 Application.Run(new XXXClientAppContext(1)); } // GC.KeepAlive(mutex); return CommConst.MAINRETURN_OTHER; } catch (Exception ex) { throw ex; } }
总结,为了忘却。
相关文章推荐
- Android 判断应用程序获取通知栏权限是否开启,以及如何跳转到应用程序设置界面
- 如何获取.NET应用程序设置文件user.config的路径
- 在C#应用程序中获取和设置IE浏览器Cookie
- SpringMVC返回json是设置编辑等消息头,消息头信息介绍(respone.setHeader,这个从网上获取)
- VS2010 MFC 用默认设置生成的应用程序GetMenu返回空值
- 获取和设置 C# 应用程序目录
- [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果
- SpringMVC返回json是设置编辑等消息头,消息头信息介绍(respone.setHeader,这个从网上获取)
- php curl获取https页面内容, 不直接输出返回结果的设置
- 获取和设置c# 应用程序目录
- Android 之 PackageManager获取的应用程序信息与AndroidManifest文件中设置的信息不一致问题
- 获取和设置c# 应用程序目录 (转)
- 获取和设置c# 应用程序目录
- Android 设置系统的返回键 和软键盘获取焦点问题
- 【Android】ListView监听上下滑动(设置滚动监听判断ListView的滚动方向同时获取屏幕高度、ListView实际高度,判断是否需要展示返回顶部按钮(具体逻辑请看代码--附有详细注释)。
- 在C#应用程序中获取和设置IE浏览器Cookie
- 获取和设置c# 应用程序目录
- 在C#应用程序中获取和设置IE浏览器Cookie
- 设置flex应用程序加载完毕后自动获取到输入焦点
- 获取和设置c# 应用程序目录