473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler Logger.EventLogger.Notify, AddressOf EvtLog

End Sub

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

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.EventDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

' Me.tv_Events.Nodes.Add(tv_Node)

End Sub
Nov 20 '05 #1
6 1175
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(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load

AddHandler Logger.EventLogger.Notify, AddressOf EvtLog

End Sub

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

tv_Node = New TreeNode(e.EventDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

' Me.tv_Events.Nodes.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*************@TK2MSFTNGP11.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.LogEventArgs)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.EventDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

' Me.tv_Events.Nodes.Add(tv_Node)

Me.tv_Events.Invoke(Nodes.Add, tv_Node)

End Sub

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

Thanks,

CJ

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:%2****************@TK2MSFTNGP12.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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler Logger.EventLogger.Notify, AddressOf EvtLog

End Sub

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

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.EventDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

' Me.tv_Events.Nodes.Add(tv_Node)

End Sub

Nov 20 '05 #5
Never mind... got it...
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:eq**************@TK2MSFTNGP12.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.LogEventArgs)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.EventDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

' Me.tv_Events.Nodes.Add(tv_Node)

Me.tv_Events.Invoke(Nodes.Add, tv_Node)

End Sub

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

Thanks,

CJ

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:%2****************@TK2MSFTNGP12.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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler Logger.EventLogger.Notify, AddressOf EvtLog

End Sub

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

tv_Node = New TreeNode(e.EventDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

' Me.tv_Events.Nodes.Add(tv_Node)

End Sub


Nov 20 '05 #6
Delegate Sub AddEventNodeDelegate (ByVal e As Logger.LogEventArgs)

Private Sub EvtLog(ByVal sender As Object, ByVal e As Logger.LogEventArgs)
tv_Events.Invoke(new AddEventNodeDelegate(AddressOf AddEventNode), New
Object() {e})
End Sub
Private Sub AddEventNode (ByVal e as Logger.LogEventArgs)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.EventDate)
tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

tv_Events.Nodes.Add(tv_Node)

End Sub

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:eq**************@TK2MSFTNGP12.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.LogEventArgs)

Dim tv_Node As TreeNode

tv_Node = New TreeNode(e.EventDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

' Me.tv_Events.Nodes.Add(tv_Node)

Me.tv_Events.Invoke(Nodes.Add, tv_Node)

End Sub

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

Thanks,

CJ

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:%2****************@TK2MSFTNGP12.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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler Logger.EventLogger.Notify, AddressOf EvtLog

End Sub

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

tv_Node = New TreeNode(e.EventDate)

tv_Node.Tag = e.Source

tv_Node.Nodes.Add(e.Source)

' Me.tv_Events.Nodes.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
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...
3
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...
7
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, ...
18
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...
4
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...
5
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...
17
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. ...
6
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...
1
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.