我有一些控制台和wpf应用程序使用的库代码.在库代码中,有一些Console.Read()调用.如果应用程序是一个控制台应用程序,我只想做那些输入读取,如果它是一个GUI应用程序 - 如何在dll中告诉应用程序是否有控制台?
我使用InstallUtil来安装我的服务,我只是无法弄清楚如何为它指定启动参数!
这是我的Installer子类:
[RunInstaller(true)]
public class ServerHostInstaller : Installer
{
private ServiceInstaller m_serviceInstaller;
private ServiceProcessInstaller m_serviceProcessInstaller;
private static string s_usage = "Usage:\ninstallutil /i /username=<user_name> /password=<user_password> NCStub.Server.Host.exe";
public ServerHostInstaller()
{
m_serviceInstaller = new ServiceInstaller();
m_serviceInstaller.ServiceName = Program.ServiceName;
m_serviceInstaller.DisplayName = Program.ServiceName;
m_serviceInstaller.StartType = ServiceStartMode.Automatic;
m_serviceProcessInstaller = new ServiceProcessInstaller();
m_serviceProcessInstaller.Account = ServiceAccount.User;
Installers.Add(m_serviceInstaller);
Installers.Add(m_serviceProcessInstaller);
}
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
string userName = this.Context.Parameters["username"];
if (userName == null)
{
Console.WriteLine(s_usage);
throw new InstallException("Missing parameter 'username'");
}
string userPass = this.Context.Parameters["password"];
if (userPass …Run Code Online (Sandbox Code Playgroud) 我需要从控制台中的特定位置读取文本,例如5,5.
如果我需要写到这个位置,它只会是:
Console.SetCursorPosition(5, 5);
Console.Write("My text");
Run Code Online (Sandbox Code Playgroud)
有什么方法可以用类似的方式阅读吗?
只是为了澄清:我不想停止接受用户的输入,即使输入不是来自用户,也不是先前打印出来的东西.我真的想要某种:Console.GetCharAtLocation(5,5)或类似的东西.