Click here to Skip to main content
12,829,103 members (38,722 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
How to Stop Hanging VB.net Application Software whenever i am using Timer


actually my code is every 10 Sec Software Auto Check and Email to Client but problem is whenever timer starts every time form can accessible by user, every time software is hanging please help me how can i need to work as backgroundly because my email code get data from customer database and after it send auto as per email address.


Please Help
Posted 21-Mar-14 23:45pm
Comments
sohail awr 22-Mar-14 12:27pm
   
First you should give your sample code where you have used the timer. After I will be able give exact solution.
hareshPrj 24-Mar-14 2:36am
   
Private Sub frmMail_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
tm_Email.Interval = 600000
tm_Email.Start()
End Sub
Private Sub tm_Email_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tm_Email.Tick
If IsConnectionAvailable() = True Then
sendMail()
else
tm_Email.Interval = 600000
End if


End Sub
private sub sendMail()
' Mail Code by CLient wise
End sub

Here is my Code please help me

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It sounds like you're using the Timer that's in the Toolbox. This is a timer that depends on Events in order to notify your application of the Tick. This also means it runs entirely on the UI thread (the thread your application started up on). When the thread is running your check every 10 seconds, it can't do other things, like update the UI (repaint it) and respond to user clicks.

The only solution to that is to move your checking code to a background thread. That is easily accomplished by removing the Timer you dropped on the form and instead use the System.Threading.Timer[^] class. It's callback will use a ThreadPool thread to execute your check code.
  Permalink  
Comments
hareshPrj 24-Mar-14 4:43am
   
how can i use please give me correct example if my code is as follows...

Private Sub frmMail_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
tm_Email.Interval = 600000
tm_Email.Start()
End Sub
Private Sub tm_Email_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tm_Email.Tick
If IsConnectionAvailable() = True Then
sendMail()
else
tm_Email.Interval = 600000
End if


End Sub
private sub sendMail()
' Mail Code by CLient wise
End sub

Here is my Code please help me
Dave Kreskowiak 24-Mar-14 9:37am
   
There are tons of examples using the Threading.Timer class all over the web. I'm not going to rewrite your code for you.

https://www.google.com/#q=system.threading.timer+example
sohail awr 25-Mar-14 14:04pm
   
You can use 2 timers 1st will check the IsConnectionAvailable() and 2nd will send the mails.

In your function IsConnectionAvailable()

Use condition

If IsConnectionAvailable() = True then
Timer2.Start()
else
Timer2.Stop()
End if

On Timer1 Tick event

Call IsConnectionAvailable()

On Timer2 Tick Event

Call Sendmail()

Also remember the Timer interval you should define in timer properties not on page load event.
Dave Kreskowiak 25-Mar-14 15:03pm
   
The problem with your solution is that it doesn't solve the problem. You're still using the Forms Timer in the Toolbox and are still running "long running" code on the UI thread, blocking it from being responsive to what the user is clicking on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170326.1 | Last Updated 22 Mar 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100