473,804 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time for a threading question

Hey Everyone,

Alright, now I cannot get this to work, I may be dumb and don't see it, but
sickness will do that every now and then.

So I have a program with 4 threads performing unique operations. Syncing
isn't really important in this, just 4 different watches that happen.

So anyways, these "watchers" are on these threads, all raise an event called
LogEvent to the main thread. LogEvent is in a module so it can be called
from anywhere (as long as its imported of course).

However, I want to hook into the shared event of LogEvent (called Notify) on
my main thread, and take some of the information that happens from this
shared event and post it on a form.

However, I keep getting an error that it can't invoke across threads.
However, I think I have done everything, but maybe I'm missing something.

here is the event handler code.

Private Sub frmMain_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

AddHandler Logger.EventLog ger.Notify, AddressOf EvtLog

End Sub

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.A dd(e.Source)

' Me.tv_Events.No des.Add(tv_Node )

End Sub
Nov 20 '05 #1
6 1189
WOW
WOW!!! Thats, Thats, Thats, WOW!!!
Wise man once said "keep it simple, stupid!"
OK, No Realy. If you need to use 4 threads then go for it
but i wouldent recommend distributing that. you could use
array and a variable and when the variable is changed
then update your treeview with the array.
-----Original Message-----
Hey Everyone,

Alright, now I cannot get this to work, I may be dumb and don't see it, butsickness will do that every now and then.

So I have a program with 4 threads performing unique operations. Syncingisn't really important in this, just 4 different watches that happen.
So anyways, these "watchers" are on these threads, all raise an event calledLogEvent to the main thread. LogEvent is in a module so it can be calledfrom anywhere (as long as its imported of course).

However, I want to hook into the shared event of LogEvent (called Notify) onmy main thread, and take some of the information that happens from thisshared event and post it on a form.

However, I keep getting an error that it can't invoke across threads.However, I think I have done everything, but maybe I'm missing something.
here is the event handler code.

Private Sub frmMain_Load(By Val sender As System.Object, ByVal e AsSystem.EventAr gs) Handles MyBase.Load

AddHandler Logger.EventLog ger.Notify, AddressOf EvtLog

End Sub

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)
Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)

tv_Node.Tag = e.Source

tv_Node.Nodes. Add(e.Source)

' Me.tv_Events.No des.Add(tv_Node )

End Sub
.

Nov 20 '05 #2
Hey Fregus,

Yea I saw that, however didn't quite explain it. I think what I'm looking
for is an explanation of how control.Invoke works. Or at least a little
more about what that means in respects to a class.

I have a class that spins off the threads (which I don't appreciate someone
calling me "stupid" for no reason. If I could have used arrays, I would
have, but I couldn't because of time issues... jacka**). anyways, these
threads raise an event logger, in which case I had a handler in my main
thread to handle anytime this shared event was fired.

So I have a DLL called Logger.dll, all shared properties/methods. Different
classes/components call this dll and its methods, primarly logEvent (sender
as object, e as LogEventArgs).

There is a public shared event called Notify, in which the main form
(frmMain) monitors. Now this works fine, the events fire, etc. However, if
you fire from another thread (IE, thread 2 calls LogEvent, which fires
Notify) it says there is an error about crossing threads and to use
control.invoke instead.

Thats what is confusing me. Does this make anymore sense?

thanks,
CJ
"Fergus Cooney" <fi******@tesco .net> wrote in message
news:uS******** *****@TK2MSFTNG P11.phx.gbl...
Hi CJ,

Do you remember that Topic: newbie thread mishap that you replied to
earlier today? Herfried and I posted there as well. Your problem may be
similar. Your solution may be the same.

Hope so anyway. :-)

Regards,
Fergus

Nov 20 '05 #3
Hi Chris,

Wow was using the full version of an acronym KISS that is often used in
training companies. "keep it simple, stupid!". I hate it - the entire
usefulness of the concept just gets wiped away by the insult at the end. ;-)

The whole problem does make more sense. It may be useful to see your
thread-spinner class and one of these threads (assuming the 4 are similar). If
possible, maybe you could post a project? If you don't want to post it here,
you may send it direct - my email is valid.

I'm going out right now and will be back in a few hours. I'd like to look
into this in depth and get a decent grasp of the concepts here.

Someone may have answered you in the meantime but in the words of Arnie..

"I'll be back"

Regards,
Fergus
Nov 20 '05 #4
Alright, So I've been screwing with this using method invoker to execute a
method on an underlying window handle.

However I have ...

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.A dd(e.Source)

' Me.tv_Events.No des.Add(tv_Node )

Me.tv_Events.In voke(Nodes.Add, tv_Node)

End Sub

And I'm getting an error on Nodes.Add in the me.tv_Events.In voke saying that
Nodes is private and cannot invoke the Add command. Suggestions?

Thanks,

CJ

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hey Everyone,

Alright, now I cannot get this to work, I may be dumb and don't see it, but sickness will do that every now and then.

So I have a program with 4 threads performing unique operations. Syncing
isn't really important in this, just 4 different watches that happen.

So anyways, these "watchers" are on these threads, all raise an event called LogEvent to the main thread. LogEvent is in a module so it can be called
from anywhere (as long as its imported of course).

However, I want to hook into the shared event of LogEvent (called Notify) on my main thread, and take some of the information that happens from this
shared event and post it on a form.

However, I keep getting an error that it can't invoke across threads.
However, I think I have done everything, but maybe I'm missing something.

here is the event handler code.

Private Sub frmMain_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

AddHandler Logger.EventLog ger.Notify, AddressOf EvtLog

End Sub

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.A dd(e.Source)

' Me.tv_Events.No des.Add(tv_Node )

End Sub

Nov 20 '05 #5
Never mind... got it...
"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:eq******** ******@TK2MSFTN GP12.phx.gbl...
Alright, So I've been screwing with this using method invoker to execute a
method on an underlying window handle.

However I have ...

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.A dd(e.Source)

' Me.tv_Events.No des.Add(tv_Node )

Me.tv_Events.In voke(Nodes.Add, tv_Node)

End Sub

And I'm getting an error on Nodes.Add in the me.tv_Events.In voke saying that Nodes is private and cannot invoke the Add command. Suggestions?

Thanks,

CJ

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hey Everyone,

Alright, now I cannot get this to work, I may be dumb and don't see it, but
sickness will do that every now and then.

So I have a program with 4 threads performing unique operations. Syncing isn't really important in this, just 4 different watches that happen.

So anyways, these "watchers" are on these threads, all raise an event

called
LogEvent to the main thread. LogEvent is in a module so it can be called from anywhere (as long as its imported of course).

However, I want to hook into the shared event of LogEvent (called Notify) on
my main thread, and take some of the information that happens from this
shared event and post it on a form.

However, I keep getting an error that it can't invoke across threads.
However, I think I have done everything, but maybe I'm missing

something.
here is the event handler code.

Private Sub frmMain_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

AddHandler Logger.EventLog ger.Notify, AddressOf EvtLog

End Sub

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)
Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.A dd(e.Source)

' Me.tv_Events.No des.Add(tv_Node )

End Sub


Nov 20 '05 #6
Delegate Sub AddEventNodeDel egate (ByVal e As Logger.LogEvent Args)

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)
tv_Events.Invok e(new AddEventNodeDel egate(AddressOf AddEventNode), New
Object() {e})
End Sub
Private Sub AddEventNode (ByVal e as Logger.LogEvent Args)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)
tv_Node.Tag = e.Source

tv_Node.Nodes.A dd(e.Source)

tv_Events.Nodes .Add(tv_Node)

End Sub

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:eq******** ******@TK2MSFTN GP12.phx.gbl...
Alright, So I've been screwing with this using method invoker to execute a
method on an underlying window handle.

However I have ...

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.A dd(e.Source)

' Me.tv_Events.No des.Add(tv_Node )

Me.tv_Events.In voke(Nodes.Add, tv_Node)

End Sub

And I'm getting an error on Nodes.Add in the me.tv_Events.In voke saying that Nodes is private and cannot invoke the Add command. Suggestions?

Thanks,

CJ

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hey Everyone,

Alright, now I cannot get this to work, I may be dumb and don't see it, but
sickness will do that every now and then.

So I have a program with 4 threads performing unique operations. Syncing isn't really important in this, just 4 different watches that happen.

So anyways, these "watchers" are on these threads, all raise an event

called
LogEvent to the main thread. LogEvent is in a module so it can be called from anywhere (as long as its imported of course).

However, I want to hook into the shared event of LogEvent (called Notify) on
my main thread, and take some of the information that happens from this
shared event and post it on a form.

However, I keep getting an error that it can't invoke across threads.
However, I think I have done everything, but maybe I'm missing

something.
here is the event handler code.

Private Sub frmMain_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

AddHandler Logger.EventLog ger.Notify, AddressOf EvtLog

End Sub

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEvent Args)
Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.Even tDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.A dd(e.Source)

' Me.tv_Events.No des.Add(tv_Node )

End Sub


Nov 20 '05 #7

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

Similar topics

65
6771
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the language's 30+ year evolution. What to you think python largest compromises are? The three that come to my mind are significant whitespace, dynamic typing, and that it is interpreted - not compiled. These three put python under fire and cause...
3
1264
by: nathan_kent_bullock | last post by:
Assume I am using a class Foo. I want to find out the modification time of the file that that class was defined in. How would I go about this? If I could find out the name of the file that Foo was defined in then it is easy, I could use os.path.getmtime(), but I can't even figure that out. I realize that this wouldn't be a completely accurate way to tell the last time this class was modified because it could inherit info from other...
7
318
by: Anthony Nystrom | last post by:
What is the correct way to stop a thread? abort? sleep? Will it start up again... Just curious... If the thread is enabling a form, if the form is disposed is the thread as well? Thanks, Anthony Nystrom
18
3272
by: Max | last post by:
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep function from kernel32 to accomplish this? My concern is that this function takes milliseconds where my program needs to be accurate to within 5 minuets, and delays may be as long as a number of days, months or whatever. Would I run into many problems...
4
1310
by: Bob | last post by:
- For cleanup, is it sufficient to set a Thread to Nothing after it's done? - It is OK to pass objects out of the thread? (dumb question maybe but I want to be sure) - What's the best way to process messages coming out of a thread? I want to queue them up, but MessageQueue doesn't look like what I need. Should I just make my own queue class? If so I'll have to worry about enumerator synchronization... a pointer to a 'best practice'...
5
3115
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when i used time.sleep in while, the function in while never executed. then i found something about Timer but couldnt realize any algorithm in my mind.
17
6440
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
6
1681
by: DarkBlue | last post by:
My application makes several connections to a remote database server via tcp/ip. Usually all is fine,but occasionally the server is down or the internet does not work and then there is the 30 sec to several minutes timeout wait for the tcp to give up. Is there anything I can do without using threads,sockets,twisted etc. to have following : pseudocode :
1
1253
by: StuartJ | last post by:
Hi, I'm trying to create a generic threading application where you can pass in any object and a number of threads, most of it is working but I'm having trouble creating multiple instances of the object handed down. The code that I've supplied should simply create msgbox with 10 different messages, but it the ProcessID gets incremented for all the threads everytime a new object is created.
2
3377
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always sitting in the sleep command and not able to be interrupted. When the time came to set the semaphore flag to false (stopping the thread), my program would have to wait up to the entire sleep time to break out of the loop. I have finally found...
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7633
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.