473,394 Members | 1,702 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,394 software developers and data experts.

how to raise a non shared event from a shared method ?

Pon
Hi everybody,

Simple question : Inside a class that has a shared method, how to raise an
event on a given instance of this class from the shared method ?
Nov 17 '06 #1
4 2644
Just pass the instance variable to the shared method. Here's a working
example:

Module Module1

Sub Main()
Dim c As New YourClass
YourClass.ChangeName(c, "funny pants")
Console.WriteLine(c.Name)
Console.Read()
End Sub

End Module

Public Class YourClass

Private m_Name As String

Public Shared Sub ChangeName(ByVal c As YourClass, ByVal newName As
String)
c.Name = newName
End Sub

Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property

End Class

Thanks,

Seth Rowe
Pon wrote:
Hi everybody,

Simple question : Inside a class that has a shared method, how to raise an
event on a given instance of this class from the shared method ?
Nov 17 '06 #2
"Pon" <po***********@laposte.netschrieb:
Simple question : Inside a class that has a shared method, how to raise an
event on a given instance of this class from the shared method ?
In order to do that you need a reference to an instance of the class. If
you implement the event using the .NET event pattern you can call the
corresponding protected 'On<event name>' method to raise the event.

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

Nov 17 '06 #3
Pon
Perfect and obvious. Thanx a lot.

"Herfried K. Wagner [MVP]" <hi***************@gmx.ata écrit dans le
message de news: uX*************@TK2MSFTNGP06.phx.gbl...
"Pon" <po***********@laposte.netschrieb:
>Simple question : Inside a class that has a shared method, how to raise
an event on a given instance of this class from the shared method ?

In order to do that you need a reference to an instance of the class. If
you implement the event using the .NET event pattern you can call the
corresponding protected 'On<event name>' method to raise the event.

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

Nov 20 '06 #4
Pon
i'm probably missing something but... uh... where's the event ?

"rowe_newsgroups" <ro********@yahoo.coma écrit dans le message de news:
11**********************@m7g2000cwm.googlegroups.c om...
Just pass the instance variable to the shared method. Here's a working
example:

Module Module1

Sub Main()
Dim c As New YourClass
YourClass.ChangeName(c, "funny pants")
Console.WriteLine(c.Name)
Console.Read()
End Sub

End Module

Public Class YourClass

Private m_Name As String

Public Shared Sub ChangeName(ByVal c As YourClass, ByVal newName As
String)
c.Name = newName
End Sub

Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property

End Class

Thanks,

Seth Rowe
Pon wrote:
>Hi everybody,

Simple question : Inside a class that has a shared method, how to raise
an
event on a given instance of this class from the shared method ?

Nov 20 '06 #5

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

Similar topics

3
by: asr | last post by:
I've a form with a button on it. How to raise (I mean to run the code within the click event of the button) without clicking the button? Is it possible to raise the events programatically.
2
by: Mauricio Rendon | last post by:
Hi, If I have a Label in a Form and need to raise the MouseUp event on the label to the Form ( Parent Control ), What must I do ? Thanks !!!
2
by: ZAky | last post by:
Why do I get a System.NullReferenceException for this script? I added the following script to a simple form with a button. <Script> public event EventHandler DoThis; static void Main() {...
12
by: Vittorio Pavesi | last post by:
Hello, is it possible to manually raise the event Elapsed of the timer object ? Vittorio
4
by: Jeremy | last post by:
I have a combobox with a SelectionChangeCommitted event handler, and am having a problem raising this event. For example, raiseEvent mycombobox.SelectionChangeCommitted gives me an error...
2
by: Pietro | last post by:
Hello, somebody know how to raise an event from a nested class? I have two classes, the class1 with 1 events, and a nested class (class2) inside the class1. So... How can I raise class1 events...
2
by: tony | last post by:
Hello !! I have a question about event. This small program below is taken from the internet and I wonder if there are any advantage to use this Onxxx in this case it's OnEventSeven instead of...
4
by: graphicsxp | last post by:
Hello, I've got a few stored procedure called made within one sqlTransaction object. If the .Rollback() method of the transaction is called, then I would like some extra code to be executed....
2
by: Sin Jeong-hun | last post by:
Suppose class Engine do something in another thread and raise events. class Engine { Thread Worker; public event ... EngineMessage; public void Start() { Worker=new Thread(new...
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
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: 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
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
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
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...

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.