如何在C#中的消息后自动关闭命令提示符窗口 [英] How to close command prompt window automatically after message in C#

查看:293
本文介绍了如何在C#中的消息后自动关闭命令提示符窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在显示消息后自动关闭命令提示窗口。



这是我的代码...





How to close the command prompt window automatically after displaying the message.

This is my code...


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace DataImport
{
    class Program
    {
        static void Main(string[] args)
        {
                string _xmlURL = ConfigurationManager.AppSettings["xmlUrl"];
                string _conString = ConfigurationManager.AppSettings["sqlConnSettings"];



                DataSet dsReportData = new DataSet();
                dsReportData.ReadXml(_xmlURL);

                DataSet dsReportData1 = new DataSet();
                dsReportData1.ReadXml(_xmlURL);
                SqlConnection connection = new SqlConnection(_conString);
                SqlConnection connection1 = new SqlConnection(_conString);
                SqlBulkCopy sbc1 = new SqlBulkCopy(connection1);

                sbc1.DestinationTableName = "StudentsRecsTable";
                sbc1.ColumnMappings.Add("Roll_Num", "Roll_Num");
                sbc1.ColumnMappings.Add("Name", "Name");
                sbc1.ColumnMappings.Add("Class", "Class");
                sbc1.ColumnMappings.Add("Father_Name", "Father_Name");
                sbc1.ColumnMappings.Add("Location", "Location");
               

                connection1.Open();
                
                sbc1.WriteToServer(dsReportData1.Tables["STUDENTS"]);

                connection1.Close();

                Console.WriteLine("All Records Imported Successfully");
                Console.Read();

            
        }
    }
}









从xml文件导入数据.............它工作正常。



但是在导入所有数据后,它获取的消息为所有记录导入成功。



在此消息之后,命令提示符窗口必须自动关闭。



请帮忙。



谢谢。





am importing the data from xml file.............it is working fine.

but after importing all data its gets message as All Records Imported Successfully.

After this message, the command prompt window must close automatically.

Please help.

Thanks.

推荐答案

你可能会在 Console.Read()操作中添加超时(您必须让用户有机会阅读该消息)。这里显示了一种方法:如何添加超时到到Console.ReadLine()?在堆栈溢出 [ ^ ]。
You may add a timeout to your Console.Read() operation (you have to give the user a chance to read the message). A way for doing that is shown here: "How to add a Timeout to Console.ReadLine()?" at Stack Overflow[^].


我假设......从您使用Console.WriteLine ...您确实希望用户看到一段时间的消息控制台应用程序关闭前的时间。



试试这个:
I assume ... from your use of Console.WriteLine ... that you do want the user to see a message for some period of time before the Console Application closes.

Try this:
Console.WriteLine("All Records Imported Successfully");
                
// Console.Read();

// wait 2 seconds before closing Console Application
System.Threading.Thread.Sleep(2000);


这篇关于如何在C#中的消息后自动关闭命令提示符窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆