<tfoot id='3N4VT'></tfoot>
    1. <small id='3N4VT'></small><noframes id='3N4VT'>

      <i id='3N4VT'><tr id='3N4VT'><dt id='3N4VT'><q id='3N4VT'><span id='3N4VT'><b id='3N4VT'><form id='3N4VT'><ins id='3N4VT'></ins><ul id='3N4VT'></ul><sub id='3N4VT'></sub></form><legend id='3N4VT'></legend><bdo id='3N4VT'><pre id='3N4VT'><center id='3N4VT'></center></pre></bdo></b><th id='3N4VT'></th></span></q></dt></tr></i><div id='3N4VT'><tfoot id='3N4VT'></tfoot><dl id='3N4VT'><fieldset id='3N4VT'></fieldset></dl></div>

      1. <legend id='3N4VT'><style id='3N4VT'><dir id='3N4VT'><q id='3N4VT'></q></dir></style></legend>
          <bdo id='3N4VT'></bdo><ul id='3N4VT'></ul>

        在窗口化应用程序中写入命令行

        时间:2023-08-27

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

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

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

              • <i id='H92tj'><tr id='H92tj'><dt id='H92tj'><q id='H92tj'><span id='H92tj'><b id='H92tj'><form id='H92tj'><ins id='H92tj'></ins><ul id='H92tj'></ul><sub id='H92tj'></sub></form><legend id='H92tj'></legend><bdo id='H92tj'><pre id='H92tj'><center id='H92tj'></center></pre></bdo></b><th id='H92tj'></th></span></q></dt></tr></i><div id='H92tj'><tfoot id='H92tj'></tfoot><dl id='H92tj'><fieldset id='H92tj'></fieldset></dl></div>
              • <tfoot id='H92tj'></tfoot>

                • 本文介绍了在窗口化应用程序中写入命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试让我的基于 WinForm 的 C# 也与命令行配合,但我很难让它发挥得很好.例如,我有这样的代码:

                  I'm trying to get my WinForm based C# to cooperate with the commandline too, but I'm having difficulty getting it to play nice. For example, I have this code:

                      [STAThread]
                      static void Main(string[] args) {
                          foreach (string s in args) {
                              System.Windows.Forms.MessageBox.Show(s);
                              Console.WriteLine("String: " + s);
                          }
                  
                          Mutex appSingleton = new System.Threading.Mutex(false, "WinSyncSingalInstanceMutx");
                          if (appSingleton.WaitOne(0, false)) {
                              try {
                                  Application.EnableVisualStyles();
                                  Application.SetCompatibleTextRenderingDefault(false);
                  
                                  //start logger
                                  Logger.singleton.makeOpen(true);
                                  Application.Run(new MainForm(false));
                              } catch (Exception) {
                              } finally {
                                  appSingleton.Close();
                                  Logger.singleton.makeOpen(false); 
                              }
                          } else {
                              System.Windows.Forms.MessageBox.Show("Sorry, only one instance of WinSync can be ran at once.");
                          }
                      }
                  }
                  

                  它应该使用 Console.WriteLine 写入控制台,但我什么也没看到,只有 MessageBox 出现.

                  It should write to the console with the Console.WriteLine, but I see nothing, only the MessageBox shows up.

                  我做错了什么?

                  推荐答案

                  尝试 AttachConsole(-1) 重定向 Console.Out,对我有用:

                  Try AttachConsole(-1) to redirect Console.Out, worked for me:

                  using System;
                  using System.Collections.Generic;
                  using System.Windows.Forms;
                  using System.Runtime.InteropServices;
                  
                  namespace PEFixer
                  {
                      static class Program
                      {
                          [DllImport("kernel32.dll")]
                          private static extern bool AttachConsole(int dwProcessId);
                  
                          /// <summary>
                          /// The main entry point for the application.
                          /// </summary>
                          [STAThread]
                          static int Main(string[] args)
                          {
                              if (args.Length > 0)
                              {
                                  AttachConsole(-1);
                                  return Form1.doTransformCmdLine(args);
                              }
                              else
                              {
                                  Application.EnableVisualStyles();
                                  Application.SetCompatibleTextRenderingDefault(false);
                                  Application.Run(new Form1());
                              }
                              return 0;
                          }
                      }
                  }
                  

                  这篇关于在窗口化应用程序中写入命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:发送“ENTER"通过串口键 下一篇:console.writeline 线程安全吗?

                  相关文章

                  最新文章

                • <legend id='EXc4m'><style id='EXc4m'><dir id='EXc4m'><q id='EXc4m'></q></dir></style></legend>
                • <tfoot id='EXc4m'></tfoot>

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

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