Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Filewatcher VB2005

Filewatcher VB2005

Scheduled Pinned Locked Moved Visual Basic
helpquestiondatabasecom
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RookieThomas
    wrote on last edited by
    #1

    Hallo all, first sorry for my English. I have a problem. I build an good aplication with a form. In this i show my college some interesting details as text in an label. They only must press a button every have an hour an see the new informations. So i take this informations from an automatik create info.txt file.. I think with the filewatcher i can show it every half an hour automaticly in the lbinfo label in form1 but there come everytime this error: Its look in German sorry . Fehler beim Erstellen des Formulars. Weitere Informationen finden Sie in Exception.InnerException. Fehler: Für den aktuellen Thread muss der STA-Modus (Single Thread Apartment) festgelegt werden, bevor OLE-Aufrufe ausgeführt werden können. Stellen Sie sicher, dass die Hauptfunktion mit STAThreadAttribute gekennzeichnet ist . This is my code for working: so its easiere to understand? Imports System.IO Module Watchertest Sub Run() ' Create a new FileSystemWatcher and set its properties. Dim watcher As New FileSystemWatcher() watcher.Path = ("c:\sms\") ' Only watch text files. watcher.Filter = "sms.txt" ' Add event handlers. AddHandler watcher.Created, AddressOf OnChanged ' Begin watching. watcher.EnableRaisingEvents = True End Sub ' Define the event handlers. Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs) ' Specify what is done when a file is changed, created, or deleted. MsgBox("File: " & e.FullPath & " " & e.ChangeType) FrmSms.Cursor = Cursors.WaitCursor FrmSms.TxtMis.Text = Nothing Call Mis_Sql_connect.sql_con() FrmSms.TxtMis.Visible = True FrmSms.TxtMis.Text = Trim(info) FrmSms.Cursor = Cursors.Default End Sub End Module :(( Thanks for help. Regards Thomas

    K 1 Reply Last reply
    0
    • R RookieThomas

      Hallo all, first sorry for my English. I have a problem. I build an good aplication with a form. In this i show my college some interesting details as text in an label. They only must press a button every have an hour an see the new informations. So i take this informations from an automatik create info.txt file.. I think with the filewatcher i can show it every half an hour automaticly in the lbinfo label in form1 but there come everytime this error: Its look in German sorry . Fehler beim Erstellen des Formulars. Weitere Informationen finden Sie in Exception.InnerException. Fehler: Für den aktuellen Thread muss der STA-Modus (Single Thread Apartment) festgelegt werden, bevor OLE-Aufrufe ausgeführt werden können. Stellen Sie sicher, dass die Hauptfunktion mit STAThreadAttribute gekennzeichnet ist . This is my code for working: so its easiere to understand? Imports System.IO Module Watchertest Sub Run() ' Create a new FileSystemWatcher and set its properties. Dim watcher As New FileSystemWatcher() watcher.Path = ("c:\sms\") ' Only watch text files. watcher.Filter = "sms.txt" ' Add event handlers. AddHandler watcher.Created, AddressOf OnChanged ' Begin watching. watcher.EnableRaisingEvents = True End Sub ' Define the event handlers. Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs) ' Specify what is done when a file is changed, created, or deleted. MsgBox("File: " & e.FullPath & " " & e.ChangeType) FrmSms.Cursor = Cursors.WaitCursor FrmSms.TxtMis.Text = Nothing Call Mis_Sql_connect.sql_con() FrmSms.TxtMis.Visible = True FrmSms.TxtMis.Text = Trim(info) FrmSms.Cursor = Cursors.Default End Sub End Module :(( Thanks for help. Regards Thomas

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      Sorry, but your posted message is very hard to understand. And I'm confused about your code. How is the Run() method called or by what control? What type of VB are you using? Perhaps it is my own limited knowledge, but I really don't understand the AddHandler code you are using. Perhaps you should think about using a timer control. That way you can check the file every half hour without the user pressing a button. For anyone else who is trying to help, I used an online translator to translate the error message to english and got this: Error with providing the form. Further information finds you in exception inside exception. Error: For the current Thread the STA mode (single Thread apartment) must be specified, before OLE calls can be implemented. Guarantee that the main function is marked by STAThreadAttribute. Perhaps you can use some break points/debugging methods to pin point exactly where the error is occuring. Sorry I couldn't help you more.

      R 1 Reply Last reply
      0
      • K Kschuler

        Sorry, but your posted message is very hard to understand. And I'm confused about your code. How is the Run() method called or by what control? What type of VB are you using? Perhaps it is my own limited knowledge, but I really don't understand the AddHandler code you are using. Perhaps you should think about using a timer control. That way you can check the file every half hour without the user pressing a button. For anyone else who is trying to help, I used an online translator to translate the error message to english and got this: Error with providing the form. Further information finds you in exception inside exception. Error: For the current Thread the STA mode (single Thread apartment) must be specified, before OLE calls can be implemented. Guarantee that the main function is marked by STAThreadAttribute. Perhaps you can use some break points/debugging methods to pin point exactly where the error is occuring. Sorry I couldn't help you more.

        R Offline
        R Offline
        RookieThomas
        wrote on last edited by
        #3

        Hallo thanks for answere. First the txt file not look every half an hour exectly so i want do this with the watcher. My vb is VB2005 netframework2. In this Code i look for change filter on the sms.txt file. Then i have an Frmsms its look informations about the productivity of some works. I want only refresh the label in this Form and the translated message from you is correct. If the txt changed a msgbox is popup i have test it.Thats all correct by the handle but if i do refresh or do anything outside this class (frmsms.label5.refresh) or else the error is pop up.. I look to command my code and post nearly. Thanks Thomas

        D 1 Reply Last reply
        0
        • R RookieThomas

          Hallo thanks for answere. First the txt file not look every half an hour exectly so i want do this with the watcher. My vb is VB2005 netframework2. In this Code i look for change filter on the sms.txt file. Then i have an Frmsms its look informations about the productivity of some works. I want only refresh the label in this Form and the translated message from you is correct. If the txt changed a msgbox is popup i have test it.Thats all correct by the handle but if i do refresh or do anything outside this class (frmsms.label5.refresh) or else the error is pop up.. I look to command my code and post nearly. Thanks Thomas

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Sorry, but this doesn't help. We still can't understand a thing you said. Dave Kreskowiak Microsoft MVP - Visual Basic

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups