由于某种原因,在我的SaveFileDialog之后,我的应用程序将永远不会显示MessageBox。我是否遗漏了什么?或者这是一个线程问题吗?
我使用VS 2010 Express作为Windows窗体应用程序运行。
我没有收到任何异常。
补充一下:当我逐步执行代码时,一切似乎都很顺利。这很奇怪,所以我认为这是一个时间问题。
正如LarsTech和其他人指出的那样,MessageBoxes确实会显示出来,但焦点消失了;换句话说,MessageBox被推到其他窗口后面或最小化了。这是一个问题。
我使用VS 2010 Express作为Windows窗体应用程序运行。
我没有收到任何异常。
补充一下:当我逐步执行代码时,一切似乎都很顺利。这很奇怪,所以我认为这是一个时间问题。
正如LarsTech和其他人指出的那样,MessageBoxes确实会显示出来,但焦点消失了;换句话说,MessageBox被推到其他窗口后面或最小化了。这是一个问题。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.IO;
namespace SpeedDating
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string filename = "test.test"; // args[0];
string ext = filename.Substring(filename.LastIndexOf('.'));
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "SpeedDating App";
dialog.RestoreDirectory = true;
dialog.CheckFileExists = false;
dialog.CheckPathExists = false;
dialog.FileName = DateTime.Now.ToString("yyyyMMdd") + ext;
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK && dialog.FileName != "")
{
try
{
FileStream outfs = File.Create(dialog.FileName);
FileStream infs = File.Open(filename, FileMode.Open);
infs.CopyTo(outfs);
infs.Close();
outfs.Close();
}
catch (NotSupportedException ex)
{
MessageBox.Show("Probably removed the original file.");
}
}
else
{
MessageBox.Show("No path found to write to.");
}
MessageBox.Show("I came here and all I got was this louzy printline");
}
}
}
catch(Exception ex)
,这应该就可以了。另外,如果我是你,我会在括号里添加if条件 ->if ((result == DialogResult.OK) && (dialog.FileName != ""))
,以确保一切都正确... - Ms. Nobody