Hack Forums
[.NET] Using timers help - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Using timers help (/showthread.php?tid=5491039)



Using timers help - selfieman231 - Dec 11, 2016

Hello hf members, today I need some help using timers in vb.net. How will I go if I want something to run in a specific part of my code ?


Let me explain my self a little:

Code
Public Function Delete()
        If System.IO.File.Exists(Globals.Location) = True Then
            System.IO.File.Delete(Globals.Location)
        End If
    End Function

I'm running this function and than closing my program right away, but since vb.net is super fast the program does not have time to delete the file and still closes leaving the file untouched. I would like to set a time for that specific code to run than continue the application and close it. Pretty much pausing the program until the file gets deleted.

How would I go into doing that?


* - Zilog80 - Dec 11, 2016

How about calling this in FormClosing() event?


* - Dialog - Dec 11, 2016

File.Delete is a blocking call, so this isn't necessary. If the file remains untouched after your program terminates, you have other problems.

And by the way - you can omit the call to File.Exists. If you call File.Delete on a non-existing file, nothing will happen.


* - selfieman231 - Dec 11, 2016

(Dec 11, 2016 03:52 PM)Dialog Wrote:  File.Delete is a blocking call, so this isn't necessary. If the file remains untouched after your program terminates, you have other problems.

And by the way - you can omit the call to File.Exists. If you call File.Delete on a non-existing file, nothing will happen.

What I meant by untouched was not deleted.. Also I check if the file is existing first before calling file.delete the file will be there anyways.


* - Dialog - Dec 11, 2016

(Dec 11, 2016 04:09 PM)selfieman231 Wrote:  What I meant by untouched was not deleted.. Also I check if the file is existing first before calling file.delete the file will be there anyways.

Read my post again. I know what untouched means. And I know what File.Delete does.


* - selfieman231 - Dec 11, 2016

(Dec 11, 2016 02:43 PM)Zilog80 Wrote:  How about calling this in FormClosing() event?

tried... but like I said vb.net is too fast... it does delete the file but I need the file for injection and inject doesnt happen because the file got deleted too fast. I need to put some type of timer after injection to delete the file. BUT after injection


Is there some way I can add a time to form.close() ? like a time before closing


Nope tried everything... There needs to be a way to add a timer anyone can help me?