473,503 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InvokeRequired not working with my Timer

Hey all, I'm having a problem with the following:

Private m_myDELEGATE As New myDELEGATE(AddressOf
ReceivingServerMessage_UIThread)
Delegate Sub myDELEGATE(ByVal ReceivingServerMessage As NetworkMessage)

Public Sub ReceivingServerMessage(ByVal objNetworkMessage As NetworkMessage)
If (Me.InvokeRequired) Then
Dim args() As Object = {objNetworkMessage}
Me.Invoke(m_myDELEGATE, args)
Else
ReceivingServerMessage_UIThread(objNetworkMessage)
End If
End Sub

Basically I use this method to pass control from a worker thread back to the
UI Thread. It works fine if its a normal thread, but when I use a timer and
call this method after the timer elapses, then Me.InvokeRequired = False and
it treats it likes its already on the main thread, and thus when I get in
ReceivingServerMessage_UIThread, I'm getting the all to familiar
"Cross-Thread operation not valid" error.

I thought Timers were just special cases of threads. What is going on
and/or what do I need to do to correct my problem?
Apr 27 '06 #1
1 1705
Sorry I jumped the gun...my thread is also making Me.InvokeRequired return
False. It must be something else I changed. I'll have to investigate more.

Sorry Disregard....for now.
"Mark Denardo" <ma*********@runbox.com> wrote in message
news:ds********************@starstream.net...
Hey all, I'm having a problem with the following:

Private m_myDELEGATE As New myDELEGATE(AddressOf
ReceivingServerMessage_UIThread)
Delegate Sub myDELEGATE(ByVal ReceivingServerMessage As NetworkMessage)

Public Sub ReceivingServerMessage(ByVal objNetworkMessage As
NetworkMessage)
If (Me.InvokeRequired) Then
Dim args() As Object = {objNetworkMessage}
Me.Invoke(m_myDELEGATE, args)
Else
ReceivingServerMessage_UIThread(objNetworkMessage)
End If
End Sub

Basically I use this method to pass control from a worker thread back to
the UI Thread. It works fine if its a normal thread, but when I use a
timer and call this method after the timer elapses, then Me.InvokeRequired
= False and it treats it likes its already on the main thread, and thus
when I get in ReceivingServerMessage_UIThread, I'm getting the all to
familiar "Cross-Thread operation not valid" error.

I thought Timers were just special cases of threads. What is going on
and/or what do I need to do to correct my problem?

Apr 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
33547
by: J. Hill | last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called. Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows...
2
4835
by: Sgt. Sausage | last post by:
Problem. Work-around. No issues, just looking to see if I'm the only one that's seen this. I just lost 3 hours (shoulda found it sooner) to the InvokeRequired on a form being somewhat...
2
4063
by: Samuel R. Neff | last post by:
I'm trying to find a good way to handle Control.InvokeRequired without duplicating four lines of code in every function/event. Typically what I've seen in books is this: If InvokeRequired Then...
5
9854
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
1
1806
by: | last post by:
Frustrated.. (I have seen other posts regarding this problem with no resolution..) I am using dotnet 1.1 with latest SP on a Win2KP box (actually 2 boxes), have even run the service on WinXP SP2...
1
9473
by: Mesan | last post by:
I'm getting a "Cross-thread operation not valid" Exception and I can't figure out why. I've got a BackgroundWorker that creates a UserControl with a whole lot of other user controls inside of...
4
25464
by: Bill McCormick | last post by:
Hello, A timer control (I think) runs in another thread apart from a main form. In the OnTick event, you can update some form control with no worries. I'm making an AsyncronousServer class...
4
2363
by: sophistiKate | last post by:
I am working with an Access 2003 database. Since adding a timer event to check for idle time to a form, a custom toolbar button that creates a snapshot has stopped working properly. Until the first...
4
10742
by: =?Utf-8?B?R3V5IENvaGVu?= | last post by:
Hi all I wrote a small demo program to understand timers and delegation - and its working fine. However, I would like to use the timer in a DLL(Class) When I compile the code: Protected...
0
7198
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
7072
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
7271
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
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.