473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to have a subroutine run constantly

2
Hello,

I am just starting out using VB .Net and am wanting to try and control my Telescope. So far I can pull one value out from the telescope but I want to have this refresh every second or so, as well as pulling out another value every second or so BUT I want to let the rest of the application run, if you know what I mean? An example - I create a label that reads the value of the telescope every second but I have another button that lets me move the telescope whilst the 1st button continues to read and display the value - Does that make any sense?
Here's what I have so far....

Expand|Select|Wrap|Line Numbers
  1. Imports System.Threading
  2. Public Class Form1
  3.  
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.  
  6.  
  7.     End Sub
  8.  
  9.     Dim Telescope As New EQMOD_SIM.Telescope
  10.     Dim ASCOMUtil As New ASCOM.Helper.Util
  11.     Public debug As String
  12.     Public ra As Double
  13.     Public dec As Double
  14.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  15.         Try
  16.             Telescope.Connected = True
  17.             debug = (Now.Hour & ":" & Now.Minute & ":" & Now.Second & " Connecting Telescope Mount...." & vbNewLine
  18.                      )
  19.             RichTextBox1.Text = debug
  20.             Thread.Sleep(3000)
  21.             If Telescope.Connected Then
  22.                 debug = (Now.Hour & ":" & Now.Minute & ":" & Now.Second & " Telescope Mount Connected" & vbNewLine
  23.                          )
  24.                 RichTextBox1.Text = debug
  25.             End If
  26.         Catch EQMODex As Exception
  27.             debug = ("EQMOD Error = " & EQMODex.Message & vbNewLine
  28.                      )
  29.             RichTextBox1.Text = debug
  30.         End Try
  31.         ra = Telescope.RightAscension()
  32.         Label2.Text = ra & vbNewLine
  33.     End Sub
  34.  
  35. End Class
  36.  
I imagine I need some form of sub routine but done have a clue how to set this up - I only started looking at VB at the weekend, never having programed since school!
Aug 23 '11 #1
3 1534
Rabbit
12,516 Expert Mod 8TB
What you're looking for is multithreading. It allows you create a new stream of execution so you can have more than one stream of code run "at the same time." Or rather it gives the illusion it's running at the same time. What's actually happening is that each stream divides up a portion of the CPU time.
Aug 23 '11 #2
blinky
2
OK, bear in mind I just started this at the weekend..... Now I have found some Microsoft documents that talk about a Backgroundworkder form so I added this. I double clicked this control on my designer and then in the code I pasted the my code, I now have:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
  2.         Do
  3.             ra = Telescope.RightAscension()
  4.             Label2.Text = ra
  5.             Thread.Sleep(2000)
  6.         Loop
  7.     End Sub
  8.  
  9. End Class

But it still wont work, I think possibly because I need to call this background process? But how do I do that?
Aug 24 '11 #3
Rabbit
12,516 Expert Mod 8TB
Microsoft has a comprehensive example here http://msdn.microsoft.com/en-us/libr...undworker.aspx
Aug 24 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jim | last post by:
Hi all, I am new to SOAP and Python. I am practicing learning SOAP with Python. I sent a request and I got the following response: <SOAPpy.Types.structType HashStringResponse at 23909440>: {}
55
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's...
2
by: singlal | last post by:
Hi, my question was not getting any attention because it moved to 2nd page; so posting it again. Sorry for any inconvenience but I need to get it resolved fast. Need your help! ...
1
by: Echo | last post by:
Ok, this is the first list comprehension that I have done. Surprisinly, it works for the most part. The problem with it is that it returns a list with two lists in it, instead of just one list....
5
by: NvrBst | last post by:
I have a bunch of variables I'd like to assign... is it possible to do it in 1 line. IE This is how I do it now int sally, jim, bill, fread, sam; sally = jim = bill = fread = sam = 5;
5
by: hn.ft.pris | last post by:
Hi: I'm a beginer of STL, and I'm wondering why none of below works: ######################################################################## .......... string str("string"); if ( str == "s" )...
3
by: Matt | last post by:
Hi All, I have the current Sub Procedure in a VBA Module. ----------------------------------------------------------------------------------------------------------------------------- Sub...
3
by: sangith | last post by:
Hi, I have question on processing the file handle in a subroutine. Here is my program without subroutine: open FH1, "<outfile" or die "cannot open the file for reading: $!\n"; while...
8
by: Perl Beginner | last post by:
I am using Win32. I have created an excel spreadsheet, formatted the columns and rows, and would like to write to the cells…all of this using Spreadsheet::WriteExcel. My issue is, my script is very...
0
by: sjdltzy | last post by:
Here is an example of Fortran ,but I can't run it in ivf 11. MODULE m TYPE t(k) INTEGER, KIND :: k REAL(k),POINTER :: vector(:) => NULL() CONTAINS FINAL :: finalize_t1s, finalize_t1v,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.