4 Replies - 8851 Views - Last Post: 09 February 2012 - 11:02 AM

#1 cheekangteh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-December 11

how to keep running a "checking file function"

Posted 08 February 2012 - 07:25 AM

i face a problem in checking file condition.
I wish to create a program that can check the condition file continuously while the program is running.

For code below that I wrote:
Private Sub StartTracking_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FILE_NAME As String = "\Program Files\Fast_Automatic_Accident_Notification_Through_SMS\Resources\contact4.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then

            MessageBox.Show("File already Exist")

                    ElseIf MessageBox.Show("File not Exist") Then

        End If

End Sub


It just can check the file condition only once, that this is only the program first load.

If I suddenly remove the file, it can’t show a message “ File not Exist” or if I suddenly receive a file and place at the folder, it can’t show me a message “File already Exist”

Kindly advice, How can I modify my code to continuously checking the file condition while the program is running.

thanks a lot.

Is This A Good Question/Topic? 0
  • +

Replies To: how to keep running a "checking file function"

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: how to keep running a "checking file function"

Posted 08 February 2012 - 07:33 AM

Did you look at this:
ElseIf MessageBox.Show("File not Exist") Then


Also why you need to check every time, instead you can check if a file exists when you need to use it. Or if the file does not exists you can use timer to check after every few minutes if a file exists.

Or you can use FileSystemWatcher to watch the changes in directory where a file exists
Was This Post Helpful? 1
  • +
  • -

#3 cheekangteh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-December 11

Re: how to keep running a "checking file function"

Posted 08 February 2012 - 08:32 PM

hi FileSystemWatcher is not support in window mobile 6 professional (compact framework), what can i solve this if i wish to use this method?

Actually the code i post before just the first step for my project. After that i wish to replace the message box to a button event.

the code should be:
Private Sub StartTracking_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FILE_NAME As String = "\Program Files\Fast_Automatic_Accident_Notification_Through_SMS\Resources\contact4.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then

           Button2_Click(sender, New System.EventArgs())

                   

        End If

End Sub

the system will operate like this:
1. i hope to run this code continually
2. once the mobile receive a file name "contact4.txt" and save at location "\Program Files\Fast_Automatic_Accident_Notification_Through_SMS\Resources\", the system will trigger the " Button2 ", if the file not exist at the location, i will not do anything.

My question:
1. May i used timer to build this function?
2. FileSystemWatcher?
3. and my code is correct if paste in program load "StartTracking_Load"? or need to paste at other function?
3. or any other method can suggest for me?
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: how to keep running a "checking file function"

Posted 08 February 2012 - 08:49 PM

Now depends on what you are trying to do there because if you want to check for the file, you can check the file once and then if it is not available, give user a chance to retry after making sure if the file exists.
But since this is a Win Mobile app, I am going to move this post to Mobile Development forum for better reply from our mobile geeks.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: how to keep running a "checking file function"

Posted 09 February 2012 - 11:02 AM

You could put this in a BackgroundWorker if you use OpenNetCF. You can use it almost exactly like it's used in WinForms/WPF/etc. It could just continue to loop while it checks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1