1

Please, how can check a record continuously from sql database using vb.net 2008 if a condition is met? Assuming connection has been established and the display of the in records has also been done. The moment the program is launched, the checking starts... I know about threading but how to implement it. Please help. Thank u in advance.

Ben

CodeMoose
  • 2,964
  • 4
  • 31
  • 56
Benniit
  • 31
  • 2
  • Is this what you're looing for: "How can SQLServer notify a vb.net application of an event?" http://stackoverflow.com/questions/6617278/how-can-sqlserver-notify-a-vb-net-application-of-an-event ? – Andrew Morton Jun 27 '13 at 17:59

1 Answers1

1

I think the easiest way is to use a Timer. Sure it'll block your UI, but you can also access your UI from there.

Let's assume that you have these things:

  • Sub Check() - Checks the database for changes. Calls Update(stuff) if there are changes
  • Sub Update(stuff) - Updates the UI with stuff.

Create a timer. In the tick event, call Check().

Alternatively, if you really want to create multiple threads, in your form load, start a thread that loops forever:

Sub CheckContinuously()
    While True
         Check()
         Threading.Thread.Sleep(1000)
    End While
End Sub

Threading.Tasks.Task.Factory.StartNew(AddressOf CheckContinously)

To stop this thing, you'll need to change the while condition. I would stick with the timer if the processing time is short.

John Tseng
  • 6,262
  • 2
  • 27
  • 35
  • If you need further help with this email me I can help you thread the things you need threaded. – Pakk Jun 27 '13 at 18:57