By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.