C# 프로젝트에서 작업 중이며 30 초 후에 파일을 삭제해야합니다. 그래서 일단 파일이 컴퓨터에 전송되면 30 초까지 계산할 소프트웨어가 필요하고 말하십시오. 스플래시 양식을 표시 한 다음 파일을 삭제하십시오. 제발 도와주세요.30 초 후에 파일을 삭제하는 방법은 무엇입니까?
그래서 제 경우에는 파일을 bin/debug 폴더에 복사합니다. 30 초 후 난 .. 파일을 삭제해야
이 내 코드입니다 :
private void button4_Click(object sender, EventArgs e)
{
//string filePath = image_print();
// MessageBox.Show(filePath, "path");
string s = image_print() + Print_image();
if (String.IsNullOrEmpty(s) || img_path.Text == "")
{
return;
}
else
{
PrintFactory.sendTextToLPT1(s);
//after this the i need the another form to pop up.. lets say i have a spalsh screen.. and it should show for 30 seconds then i need to delete the file.. where i have codes bwlow
string Filename = img_path.Text;
if (string.IsNullOrEmpty(Filename))
return;
if (Filename.ToCharArray().Intersect(Path.GetInvalidFileNameChars()).Any())
return;
File.Delete(Path.Combine(@"\\bin\Debug", Filename));
}
}
private string image_print()
{
OpenFileDialog ofd = new OpenFileDialog();
string path = "";
string full_path = "";
string filename_noext = "";
ofd.InitialDirectory = @"C:\ZTOOLS\FONTS";
ofd.Filter = "GRF files (*.grf)|*.grf";
ofd.FilterIndex = 2;
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
filename_noext = System.IO.Path.GetFileName(ofd.FileName);
path = Path.GetFullPath(ofd.FileName);
img_path.Text = filename_noext;
//MessageBox.Show(filename_noext, "Filename"); - - -> switching.grf
// MessageBox.Show(full_path, "path");
//move file from location to debug
string replacepath = @"\\bin\Debug";
string fileName = System.IO.Path.GetFileName(path);
string newpath = System.IO.Path.Combine(replacepath, fileName);
// string newpath = string.Empty;
if (!System.IO.File.Exists(filename_noext))
System.IO.File.Copy(path, newpath);
filename_noext = img_path.Text;
MessageBox.Show(filename_noext, "path");
}
if (string.IsNullOrEmpty(img_path.Text))
return "";//
StreamReader test2 = new StreamReader(img_path.Text);
string s = test2.ReadToEnd();
return s;
}
private string Print_image()
{
//some codes
return s;
}
Thread.Sleep (30000) ?? – Fratyx
어떤 부분이 당신을 트립하고 있습니다. 30 초를 기다리고 있니? [타이머 클래스] (http://msdn.microsoft.com/en-us/library/system.windows.forms.timer (v = vs.110) .aspx)를 살펴보십시오. –
시작 화면이 있습니까? – Shaharyar