Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello

I have this code in my MainForm:

CheckForIllegalCrossThreadCalls = False
Dim CountTrafficThread As New Threading.Timer(New Threading.TimerCallback( AddressOf CountTraffic), Nothing, 0, 500)


it works good but, when I call a dialog box from this form, the timer is stopped and counter can not count. If i use a Timer Object from toolbox it work good even after calling dialog box.

please help me.

thank you

What I have tried:

Just search on the web to find solution
Posted
Updated 16-Apr-17 5:29am
Comments
[no name] 16-Apr-17 8:01am    
"CheckForIllegalCrossThreadCalls = False", probably one of the worse things you can do.

CheckForIllegalCrossThreadCalls = False

Remove that line of code and forget it even exists. You're setting yourself up for bugs that are very difficult to replicate and fix.

The timer doesn't stop. It's still running. The problem is your code has the thread that the timer event is firing on blocked with the dialog so the thread can't do anything else until the dialog is dismissed.

How do you fix it? Don't know. We can only see two lines of code and we know nothing of the design of your code. But, given that you put in the CheckForIllegalCrossThreadCalls line, your code is probably going to need to be rewritten to do things correctly instead of patching crap together to force it to work the wrong way.
 
Share this answer
 
thank you

I removed "CheckForIllegalCrossThreadCalls = False"

here is rest of code:

Sub CountTraffic(byval var As Object)
_CountUnauthorized +=1
End Sub

this was a test project to work with thread.

"_CountUnauthorized" is a form level variable. because I removed that line I put the value in a form level variables and with Timer Object I read the variables and show in Label. but how can I solve of mentioned problem.

sorry I am beginner in thread...

thank you
 
Share this answer
 
v2
Comments
[no name] 16-Apr-17 12:04pm    
"how can I solve of mentioned problem", you might *think* you mentioned a problem but you didn't.
And this isn't a solution.
"I am beginner", I know it's hard to believe, we can tell. There is no need to tell people this.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900