473,396 Members | 2,061 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,396 software developers and data experts.

shared events possible?

Dear all,

is it not possible to have shred events?

Thanks,

Boni

error BC30600: 'WithEvents' variable does not raise any instance events that
are accessible to 'Class A."

Friend Class A

Public Shared WithEvents MyEvents As New cMyEvents

End Class

Class cMyEvents

Public Shared Event MyStarEvent

Shared Sub Raisestart()

RaiseEvent MyStarEvent()

End Sub

End Class
Nov 21 '05 #1
3 10175

Boni wrote:
Dear all,

is it not possible to have shred events?
I think it is.
error BC30600: 'WithEvents' variable does not raise any instance events that
are accessible to 'Class A."


The error message is actually useful here. If you declare an object
*variable* WithEvents, that means that it is going to hold an
*instance* of that class, so there must be *instance* events for it to
listen for. cMyEvents doesn't have any *instance* events so object
variables of type cMyEvents will never receive any events, so can't be
declared WithEvents.

That make sense? :)

Your event class definition is fine:

Class cMyEvents

Public Shared Event MyStarEvent()

Shared Sub Raisestart()
RaiseEvent MyStarEvent()
End Sub
End Class

So now we have defined a shared event, cMyEvents.MyStarEvent. We just
need to set up a handler, so let's try:

Friend Class A
Public Shared Sub HandleStarEvent() Handles cMyEvents.MyStarEvent

End Sub
End Class

But this doesn't compile - it seems that 'Handles', like 'WithEvents',
is only to be used for *instance* event handling. But we are not done
yet! Now we try:

Friend Class A

Public Shared Sub HandleStarEvent()

End Sub

Public Shared Sub StartListening()
AddHandler cMyEvents.MyStarEvent, AddressOf HandleStarEvent
End Sub

End Class

and this works! You must of course remember to call StartListening at
some point :)

--
Larry Lard
Replies to group please

Nov 21 '05 #2
Thanks for great explantion Larry!
"Larry Lard" <la*******@hotmail.com> schrieb im Newsbeitrag
news:11*********************@g44g2000cwa.googlegro ups.com...

Boni wrote:
Dear all,

is it not possible to have shred events?


I think it is.
error BC30600: 'WithEvents' variable does not raise any instance events
that
are accessible to 'Class A."


The error message is actually useful here. If you declare an object
*variable* WithEvents, that means that it is going to hold an
*instance* of that class, so there must be *instance* events for it to
listen for. cMyEvents doesn't have any *instance* events so object
variables of type cMyEvents will never receive any events, so can't be
declared WithEvents.

That make sense? :)

Your event class definition is fine:

Class cMyEvents

Public Shared Event MyStarEvent()

Shared Sub Raisestart()
RaiseEvent MyStarEvent()
End Sub
End Class

So now we have defined a shared event, cMyEvents.MyStarEvent. We just
need to set up a handler, so let's try:

Friend Class A
Public Shared Sub HandleStarEvent() Handles cMyEvents.MyStarEvent

End Sub
End Class

But this doesn't compile - it seems that 'Handles', like 'WithEvents',
is only to be used for *instance* event handling. But we are not done
yet! Now we try:

Friend Class A

Public Shared Sub HandleStarEvent()

End Sub

Public Shared Sub StartListening()
AddHandler cMyEvents.MyStarEvent, AddressOf HandleStarEvent
End Sub

End Class

and this works! You must of course remember to call StartListening at
some point :)

--
Larry Lard
Replies to group please

Nov 21 '05 #3
"Boni" <oilia@nospam> schrieb:
is it not possible to have shred events?


In addition to the other reply, it's possible to use the 'AddHandler'
statement to add a handler to a shared event.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

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

Similar topics

11
by: Ian Bell | last post by:
Apologies for the last post; got the topic wrong. What is the current thinking on the best way to solve the shared data problem i.e. accesssing a shared variable in a non atomic way can give...
9
by: Invalidlastname | last post by:
Hi, We developed some assemblies which use EnterpriseServices queued components. In order to use EnterpriseServices, these assemblies need to be installed into GAC. I used the pre-build and...
10
by: Daniel Fernandes | last post by:
Hi there Let's say due to several reasons I have an ASP.Net application that has a database access class that stores a database connection in a shared member : public class dataaccess ...
13
by: Nak | last post by:
Hi there, In VB6 if I wanted to make a shared application so to speak I would create an ActiveX EXE. This would allow me to expose objects of the application but only have 1 instance loaded. ...
4
by: Rubbrecht Philippe | last post by:
Hi there, I would like to develop an interface that when implemented in a class requires a number of shared properties or methods to be available. It seems a Shared Member can not be used as...
5
by: Simon | last post by:
Hi all, We have an ASP.NET 1.1 application running on IIS6 on Server 2003. Most of the base objects we are using in this application are taken from a windows application also written by us. We...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
4
by: herbert | last post by:
I am coding a dozen "background" realtime apps for factory automation in .NET 2.0. The apps need to share a common memory as there are lots of variables to be shared (and synchronized of...
2
by: =?Utf-8?B?V3Vqb29k?= | last post by:
I am trying to solve the following take home assignment problem. I am not sure whether to use Hashtables, events and shared members or could it be done more easily? Also, do I need to implement a...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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
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...
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.