c# - How to delete the file after 30 seconds? -
c# - How to delete the file after 30 seconds? -
i working on c# project , need file deleted after 30 seconds. 1 time file sent machine need software count till 30 seconds , lets say.. show splash form , delete file. please help me out.
so in case copying file bin/debug folder. , after 30 seconds need delete file..
this code:
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 need form pop up.. lets have spalsh screen.. , should show 30 seconds need delete file.. 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 location 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)) homecoming "";// streamreader test2 = new streamreader(img_path.text); string s = test2.readtoend(); homecoming s; } private string print_image() { //some codes homecoming s; }
create new form utilize splashscreen
.
in splashscreen's constructor, take file path parameter , start timer:
string filepath; public splashscreen(string filetodeletepath) { initializecomponent(); this.filepath = filetodeletepath; system.windows.forms.timer timer1 = new system.windows.forms.timer(); timer1.interval = 3000; timer1.tick += timer1_tick; timer1.start(); } void timer1_tick(object sender, eventargs e) { //delete file if (!string.isnullorempty(filepath)) file.delete(filepath); //dispose form after deleting file this.close(); }
how utilize splashscreen
:
else { printfactory.sendtexttolpt1(s); //after need form pop up.. lets have spalsh screen.. , should show 30 seconds need delete file.. 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)); //remove line, it'll done in splashscreen string filepath = path.combine(@"\\bin\debug", filename); //create path of file removed //splashscreen splashscreen splash = new splashscreen(filepath); splash.show(); }
the splashscreen
instance automatically disposed after deleting file, , it'll not block main thread (ui).
c# wpf visual-studio-2010 visual-studio delete-file
Comments
Post a Comment