我已经使用C#.net创建了一个控制台应用程序,并且它在我的本地系统上工作正常但是当我将bin文件夹复制到Server并运行.exe文件时发生了注意(黑屏进入并在一秒钟内消失)我有在Sql Server Profiler上检查一切工作正常我用过Try Catch Block检查异常但没有任何效果..... 我的代码是
private static void Main(string[] args)
{
try
{
// Get All User
var userList = BLLMailAlert.GetAllSubscribedUser();
// Send UserID as Parameter and Find Tenders For Users
var InCulture = new CultureInfo("hi-IN");
var currentDate = DateTime.Now;
var fromEmail = string.Empty;
var toEmail = string.Empty;
foreach (var user in userList)
{
// For Each AlertId Find Template Name and EmailId
var userDetail = BLLMailAlert.GetUserAllDetail(user.AlertID);
var userTenders = BLLMailAlert.GetAllTenderForPaidUser(user.UserID).ToList();
if (userTenders.Count > 0)
{
// According to TemplatePath Send tender Alert to each user
var TemplatePath = userDetail.UserTypeTemplate.EmailTemplatePath;
var HeaderTemplateForPaidUser = ConfigurationManager.AppSettings["HeaderTemplateForPaidUser"];
var FooterTemplateForPaidUser = ConfigurationManager.AppSettings["FooterTemplateForPaidUser"];
toEmail = userDetail.Email;
fromEmail = ConfigurationManager.AppSettings["AdminMail"];
var sbMail = new StringBuilder();
using (var sReader = new StreamReader(HeaderTemplateForPaidUser))
{
sbMail.Append(sReader.ReadToEnd());
sbMail.Replace("{Name}", userDetail.Name);
sbMail.Replace("{CurrentDate}", currentDate.ToString("D"));
}
foreach (var tender in userTenders)
{
using (var sReader = new StreamReader(TemplatePath))
{
sbMail.Append(sReader.ReadToEnd());
sbMail.Replace("{TenderTitle}", tender.TenderTitle);
sbMail.Replace("{TenderID}", tender.TenderID.ToString("####"));
sbMail.Replace("{TenderType}", tender.TenderTypeName);
sbMail.Replace("{TenderValue}", tender.TenderValue.ToString("₹ 0,0", InCulture));
sbMail.Replace("{TenderEMD}", tender.TenderEMD);
sbMail.Replace("{Location}", tender.Location);
sbMail.Replace("{OrgName}", tender.OrgName);
sbMail.Replace("{LastDateForSubmission}", tender.LastDateForSubmission.ToString("d"));
sbMail.Replace("{SubProductCatName}", tender.SubProductCatName);
sbMail.Append("<br />");
}
}
using (var sReader = new StreamReader(FooterTemplateForPaidUser))
{
sbMail.Append(sReader.ReadToEnd());
}
var mailReport = BLLMailAlert.SendTenderAlert(fromEmail, toEmail, sbMail.ToString());
if (mailReport)
{
Console.WriteLine("Tender Alert Send " + currentDate);
Console.WriteLine("Press enter 1...");
Console.ReadLine();
// using (var writer = new StreamWriter("log.txt"))
// {
// writer.WriteLine("Tender Alert Send" + currentDateTime);
// }
}
else
{
Console.WriteLine("Unable To Send Tender Alert" + currentDate);
Console.WriteLine("Press enter 2...");
Console.ReadLine();
// using (var writer = new StreamWriter("log.txt"))
// {
// writer.WriteLine("Unable To Send Tender Alert" + currentDateTime);
// }
}
}
else
{
Console.WriteLine("No Tender Found" + currentDate);
Console.WriteLine("Press enter 3...");
Console.ReadLine();
}
}
}
catch (Exception ex)
{
Console.Write(ex);
Console.WriteLine("Press enter 4...");
Console.ReadLine();
}
}
我试过写过Console.WriteLine(“嘿Vishal”); 在主要但它仍然无法正常工作
答案 0 :(得分:1)
你确定它不起作用吗?当您通过双击.exe运行控制台应用程序时,它将在完成时退出,除非您已告诉它等待某事。如果您打开命令窗口(cmd.exe)并通过命令行运行应用程序会发生什么 - 这样命令窗口将保持打开状态,您可以在关闭之前看到任何控制台输出。
这是否会在您的服务器上运行?
private static void Main(string[] args)
{
Console.WriteLine("Hello World");
Console.WriteLine("Enter to exit...");
Console.ReadLine();
}
答案 1 :(得分:0)
最后我使用Console.ReadLine(“some text”)来读取异常消息,因为异常消息将在黑屏上显示,但它很早就消失了所以我使用了Console.ReadLine(“some text”),我可以通过它找出问题所在..........