VB.NET - 'WithEvents' variables cannot be typed as arrays - Now what?

I have a class that I want to use several instances of... the class raises events to notify me of completed things.

everything works fine as 1 instance... however if i try to make an array of the class i get the error:

 'WithEvents' variables cannot be typed as arrays

is there a better way to do this?
mcaincAsked:
Who is Participating?
 
DabasConnect With a Mentor Commented:
Hello mcainc,

The way to overcome this is as per snippet

Regards,

Dabas
Private WithEvents client As IRCClient 
Private ClientArray() as IRCClient 
Somewhere else in your code, you might have something like: 
For Each client in ClientArray
...Raise your events here for the single client within the array
Next 
 

Open in new window

0
 
Wayne Taylor (webtubbs)Commented:
Can you show the relevant code?
0
 
mcaincAuthor Commented:
Private WithEvents client() As IRCClient

this gives the error

Private WithEvents client As IRCClient

this works fine
0
 
Wayne Taylor (webtubbs)Commented:
mcainc

You'll have to use a collection of your objects, then use AddHandler on each item in the collection to handle each objects events.

Wayne
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.