Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I get timer to run independently & allow menu to activate something else

Posted on 2004-11-16
8
Medium Priority
?
225 Views
Last Modified: 2010-04-23
I have a form which immeiately starts a timer, it reads a database & compiles the number of pages for a report

The result of this, then changes the text on a menu to indicate the number of pages when the timer is finished

this timer can or cannot be time consuming depending on the number of pages it has to calculate

I want the timer to run independently, but it is stopping other functions that are in the menu

I get a message saying, 'not responding' on the form text, however this is resolved when the timer is finished

I want the user to be able to activate menu options whilst the timer is running until completion

I thought about adding a 2nd menu control, but it appears to be inactive, because when I run the app it is not visible, so I don't quite understand the rules for adding a second menu

any help much appreciated
0
Comment
Question by:bemson
  • 4
  • 4
8 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12603687
YOu can rn timer in a different thread

Use
    System.Timers.Timer
instead of
    System.Windows.Forms.Timer

(in the toolbox under "components", not "windows forms")

The raised event will run in a different thread.

0
 

Author Comment

by:bemson
ID: 12607895
Thanks for your reply

 It sounds a logical solution, however,

using the original concept I had where the timer activates on load of form 2, I still get the same effect with the component timer

trying a new approach, I still get the same result
form1 loads the form with the timer in it, so, to try & use another logic I started the timer in the 1st form (at it's conclusion), before loading the form that needed the result, I still get same result where I get the message 'Not responding' (when selecting the menu)

it seems that nothing will activate on the form until the timer has finished.

I have even put in doevents which does not seem to help


thanks for taking an interest in my problem
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12608119
What if you put timer completely into different thread
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:bemson
ID: 12608210
Thanks for your prompt reply

I am not exactly sure of the term thread, I presumed it meant activating that process at a different logical point in the app which I thought I had done by getting the timer to run from form 1 instaed of form 2

could you please enlighten me further on your interpretation of thread & how to achieve your solution
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 800 total points
ID: 12608362
here is tutorial on multythreading
http://www.wrox.com/books/1861007132.htm


 If your application is going to perform a task that could take a
long time, such as parsing through a large recordset or performing a complex series
of mathematical calculations, you can push that processing off to its own thread so
that the rest of your application is still accessible. In VB6, , the best you could do to
keep the rest of the application from appearing to be locked was to use the DoEvents
method.
Examine this code, which is written for VB.NET. Here you have some code for
button4. This code calls the BeBusy routine, which has a loop in it to just to take up
time. However, while in this loop, you are consuming the thread for this application,
and the UI will not respond while the loop is running.
The good news is the VB.NET IDE runs on
a separate thread, so if you find yourself waiting forever, just click on the IDE and
choose Stop Debugging from the Debug menu.

Private Sub button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles button4.Click
BeBusy()
End Sub

Sub BeBusy()
Dim i As Decimal
For i = 1 To 10000000
‘do nothing but tie up app
Next
Beep()
End Sub

To create a thread, you must use the System.Threading.Thread class. In the creation
of the class, you pass in the name of the procedure or method you want to run on that
thread. You preface the procedure or method name with the AddressOf operator. Your
code would look like this:

Dim busyThread As New System.Threading.Thread(AddressOf BeBusy)

To fix the code and keep BeBusy from consuming the main program thread, you have
now created a new thread and will run BeBusy on that thread. However, that line of
code isn’t enough. Next, you must call the Start method on that new thread. With
VB.NET, calling BeBusy on its own thread would look like this:

Private Sub button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles button4.Click
Dim busyThread As New System.Threading.Thread(AddressOf BeBusy)
busyThread.Start()
End Sub

No changes are required to the BeBusy procedure. If you now run this code, the interface
will remain active while BeBusy is running. The Beep in BeBusy will let you
know when the procedure has finished running.
0
 

Author Comment

by:bemson
ID: 12608517
Thanks for your info re threads. I am using vb.net 2002

I will try to relate to this new process (for me) & attempt to apply it & see what transpires

I have to go out & will not be back for 7 hours, I will then attempt to implement your suggestion as described above, so I do not expect to be able to get back to you for about 24 hours

your assistance is much appreciated.
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12608623
take your time and good luck
0
 

Author Comment

by:bemson
ID: 12620929
I have been able to successfully implement your suggestion

Your interest & information is much appreciated
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question