日期:2014-05-18  浏览次数:20765 次

外部程序启动我的程序,并给我的程序传参数
我最近做一个客户端程序,看开发文档中,服务器程序会主动来启动我的程序,并把服务器的监听端口号传给我的程序,我不太明白,服务器如何能够给我的程序传参数?
原文是we will pass the port number on the argument line of your process。求高人指点

------解决方案--------------------
C# code

    static class Program
    {
//外部调用方式:Win.exe <root><userid>1001</userid><password></password></root>

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
        string str = (string.Format(("{0}"), args));

        //str 就是传递过来的值
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            MessageBox.Show(str);
        }
    }

------解决方案--------------------
都已经说的很清楚了
we will pass the port number on the argument line of your process
就是他会执行类似于xxx.exe port这样的命令行形式来调用你的程序,参数就在main函数的args中。