<i id='C86iL'><tr id='C86iL'><dt id='C86iL'><q id='C86iL'><span id='C86iL'><b id='C86iL'><form id='C86iL'><ins id='C86iL'></ins><ul id='C86iL'></ul><sub id='C86iL'></sub></form><legend id='C86iL'></legend><bdo id='C86iL'><pre id='C86iL'><center id='C86iL'></center></pre></bdo></b><th id='C86iL'></th></span></q></dt></tr></i><div id='C86iL'><tfoot id='C86iL'></tfoot><dl id='C86iL'><fieldset id='C86iL'></fieldset></dl></div>
      <legend id='C86iL'><style id='C86iL'><dir id='C86iL'><q id='C86iL'></q></dir></style></legend>
    1. <small id='C86iL'></small><noframes id='C86iL'>

        • <bdo id='C86iL'></bdo><ul id='C86iL'></ul>
        <tfoot id='C86iL'></tfoot>

        如何在我的 C# 控制台应用程序中使用命令行参数

        时间:2023-08-27
          <i id='WHJGa'><tr id='WHJGa'><dt id='WHJGa'><q id='WHJGa'><span id='WHJGa'><b id='WHJGa'><form id='WHJGa'><ins id='WHJGa'></ins><ul id='WHJGa'></ul><sub id='WHJGa'></sub></form><legend id='WHJGa'></legend><bdo id='WHJGa'><pre id='WHJGa'><center id='WHJGa'></center></pre></bdo></b><th id='WHJGa'></th></span></q></dt></tr></i><div id='WHJGa'><tfoot id='WHJGa'></tfoot><dl id='WHJGa'><fieldset id='WHJGa'></fieldset></dl></div>
        1. <tfoot id='WHJGa'></tfoot>

              <bdo id='WHJGa'></bdo><ul id='WHJGa'></ul>
                <tbody id='WHJGa'></tbody>

                  <small id='WHJGa'></small><noframes id='WHJGa'>

                • <legend id='WHJGa'><style id='WHJGa'><dir id='WHJGa'><q id='WHJGa'></q></dir></style></legend>

                • 本文介绍了如何在我的 C# 控制台应用程序中使用命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在编写一个 url 缩短器应用程序,我还想使用 C# 创建一个控制台应用程序,以将 URL 推送到我也创建的 WCF 服务.

                  I am writing a url shortener app and I would like to also create a console app with C# to push the URLs to a WCF service which I have also created.

                  WCF 应用程序将缩短此 URI 上的 url;

                  WCF app will shorten the url on this URI;

                  http://example.com/shorten/http://exaple.com

                  所以我想要的就是这样.

                  so what I want is just that.

                  我的控制台 exe 文件将位于 c:dev 文件夹和 Windows 命令行中,我想这样做;

                  My console exe file will be sitting inside c:dev folder and on Windows command line, I would like to do this;

                  c:dev>myapp -throw http://example.com

                  c:dev>myapp -throw http://example.com

                  我想通过这种方法与该服务交谈.谈话部分没有问题.但问题是我如何在命令行上提供这个 -throw 东西并获得响应并将该响应放在命令行上并提供一种方法将其复制到剪贴板.我在这里问太多了吗?:S 我不知道.

                  with this method I would like to talk to that service. there is no problem on talking part. But the problem is how can I supply this -throw thing on the command line and get a response and put that response on the command line and supply a method to copy that to the clipboard. Am I asking too much here? :S I don't know.

                  您能否指导我到某个地方我可以找到相关信息,或者您能给我一个示例代码吗?

                  Could you direct me somewhere that I can find information on that or could u please give me an example code of this?

                  谢谢.

                  我试过下面的代码;

                      class Program {
                  
                      static void Main(string[] args) {
                  
                          if (args[0] == "-throw") {
                  
                              System.Windows.Forms.Clipboard.SetDataObject(args[1]);
                              Console.WriteLine(args[1] + " has been added to clipboard !");
                              Console.ReadLine();
                  
                          }
                  
                      }
                  }
                  

                  我收到以下错误;

                  C:AppsArgsTryArgsTryinDebug>ArgsTry- 扔人

                  C:AppsArgsTryArgsTryinDebug>ArgsTry -throw man

                  未处理的异常:System.Threading.ThreadStateException:当前线程必须设置为单线程OLE 之前的线程单元 (STA) 模式可以拨打电话.确保您的主函数具有 STAThreadAttribute标在上面.在System.Windows.Forms.Clipboard.SetDataObject(对象数据,布尔副本,在 t32 retryTimes 中,Int32 重试延迟)在System.Windows.Forms.Clipboard.SetDataObject(对象数据)在ArgsTry.Program.Main(String[] args) 在c:appsArgsTryArgsTryProgram.cs:第 14 行

                  Unhandled Exception: System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensur e that your Main function has STAThreadAttribute marked on it. at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy, In t32 retryTimes, Int32 retryDelay) at System.Windows.Forms.Clipboard.SetDataObject(Object data) at ArgsTry.Program.Main(String[] args) in c:appsArgsTryArgsTryProgram.cs: line 14

                  C:AppsArgsTryArgsTryinDebug>

                  C:AppsArgsTryArgsTryinDebug>

                  推荐答案

                  向控制台应用程序传递参数很简单:

                  Passing arguments to a console application is easy:

                  using System;
                  
                  public class CommandLine
                  {
                     public static void Main(string[] args)
                     {
                         for(int i = 0; i < args.Length; i++)
                         {
                             if( args[i] == "-throw" )
                             {
                                 // call http client args[i+1] for URL
                             }
                         }
                     }
                  }
                  

                  至于剪贴板,见:

                  http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx

                  这篇关于如何在我的 C# 控制台应用程序中使用命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:控制台应用程序在鼠标单击时冻结 下一篇:在控制台中删除以前写的行

                  相关文章

                  最新文章

                  1. <tfoot id='P77st'></tfoot>

                        <bdo id='P77st'></bdo><ul id='P77st'></ul>
                    1. <legend id='P77st'><style id='P77st'><dir id='P77st'><q id='P77st'></q></dir></style></legend>
                      <i id='P77st'><tr id='P77st'><dt id='P77st'><q id='P77st'><span id='P77st'><b id='P77st'><form id='P77st'><ins id='P77st'></ins><ul id='P77st'></ul><sub id='P77st'></sub></form><legend id='P77st'></legend><bdo id='P77st'><pre id='P77st'><center id='P77st'></center></pre></bdo></b><th id='P77st'></th></span></q></dt></tr></i><div id='P77st'><tfoot id='P77st'></tfoot><dl id='P77st'><fieldset id='P77st'></fieldset></dl></div>

                      <small id='P77st'></small><noframes id='P77st'>