G
G
GLPavel2016-11-30 11:27:44
C++ / C#
GLPavel, 2016-11-30 11:27:44

How to run a console application in C#?

There is a simple C# application, written in a notepad, it is a console one.
Accordingly, at startup, the console is launched and while the console is running, it looks so-so on slow PCs. Well, the question itself "How to launch a console application in C# hidden?", so that the console is minimized or not displayed to the user at all, the code for a greater understanding of the problem.

using System;
using System.Diagnostics;
using System.IO;
namespace Start1CEnterprise
{
  class StartEnterprise
  {	
    static void Main()
    {
      // сдесь задаем переменные версии нашей базы на сервере
      string vers = "";
      // режим запуска оставил просто так, но работает
      string ForS = "";
      // Сервер
      string server = "";
      // База
      string bases = "";
      // счетчик перебираемых атрибутов
      int chek = 0;
      // переберем все строки в файле и сохраним в переменные указанные выше
      string[] param = File.ReadAllLines("param.txt");
      foreach(string par in param)
      {
        switch(chek)
        {
          case 0: vers = par;break;
          case 1:	ForS = par;break;
          case 2:	server = par;break;
          case 3:	bases = par;break;
        }
        ++chek;  
      }
      
      
      string atributs = @"... /"+ForS+" "+server+@"\"+bases+@" ...";
      
      string[] adress = new string[] 
      {
        @"C:\Program Files (x86)\..\"+vers+@"\bin\...exe",
        @"C:\Program Files (x86)\..\"+vers+@"\bin\...exe",
        @"C:\Program Files\..\"+vers+@"\bin\...exe",
        @"C:\Program Files\..\"+vers+@"\bin\...exe",
        @"\\..\..\"+vers+@"\bin\...exe",
        @"\\..\..\"+vers+@"\bin\...exe"				
      };
      // проверим все адреса 
      foreach(string adres in adress)
      {	
        // проверим есть ли файл по адресу
        if(File.Exists(adres))
        {
          // запустим его
          Process.Start(adres, atributs);
          // не продолжаем перебирать и выйдем из цикла
          break;
        }
        
      }
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-11-30
@GLPavel

In the project properties, you can change the build type to Windows Application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question