Question Help with myltitasking

blinky

New member
Joined
Aug 27, 2011
Messages
2
Programming Experience
Beginner
I am writing a small app that will query where my telescope is pointing, so far I can connect to the telescope and can grab the value but I want to let it run continuously so that I can do other things with the program!
I am trying to figure out how to use the Backgroundworker but I cant get it to start running - I dont know what the code is to call my Backroundworker process, if you know what I mean?
Here is the code I have so far... The sub I am trying to get to run automatically is at the end.
Imports
System.Threading
Imports
System.ComponentModel
Public
Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub


 


Dim Telescope As New EQMOD_SIM.Telescope


Dim ASCOMUtil As New ASCOM.Helper.Util


Public debug As String


Public ra As Double


Public dec As Double



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Try

Telescope.Connected =
True

debug = (Now.Hour &
":" & Now.Minute & ":" & Now.Second & " Connecting Telescope Mount...." & vbNewLine)

RichTextBox1.AppendText(debug)


If Telescope.Connected Then

debug = (Now.Hour &
":" & Now.Minute & ":" & Now.Second & " Telescope Mount Connected" & vbNewLine)

RichTextBox1.AppendText(debug)


End If


Catch EQMODex As Exception

debug = (
"EQMOD Error = " & EQMODex.Message & vbNewLine)

RichTextBox1.AppendText(debug)


End Try


End Sub


Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork


Do

ra = Telescope.RightAscension()

Label2.Text = ra


Thread.Sleep(2000)


Loop


End Sub


End
Class

 
You call RunWorkerAsync to raise the DoWork event. You do your background work (and ONLY your background work) in the DoWork event handler. If you need to update the UI, you do so in the ProgressChanged and/or RunWorkerCompleted event handlers. Check this out:

Using the BackgroundWorker Component
 
Back
Top