Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

invoking NoParamsDelagate within a class

Posted on 2006-10-22
5
Medium Priority
?
249 Views
Last Modified: 2010-04-23
Hi Experts,

I would like to know how i could use this code within my class

Dim dlg As New NoParamsDelagate(AddressOf CloseConnect)
Me.Invoke(dlg)

this works within a form class but when i place this into another class i get a design time error tessling me that invoke is not a member of my class,

How can i fix this??

Cheers,

Tom
0
Comment
Question by:TommyTwoPints
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 10

Assisted Solution

by:Kinger247
Kinger247 earned 400 total points
ID: 17783887
The invoke method can only be used on a form  or control.

As in MSDN : Executes the specified delegate, on the thread that owns the control's underlying window handle, with the specified list of arguments.

What are you trying to do ?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 1000 total points
ID: 17783894
Invoke is function of Control class and can be applied to any instance of Control-derived class. It is used to call function in the context of thread which created this control. .NET control can be updated only from the thread which created it. In other classes, not derived from Control, Invoke is not necessary, because there is no thread restriction. If you have CloseConnect function in the class which is not derived from Control, just call function directly:
CloseConnect()

If you have CloseConnect function in Control-derived class, and want to invoke it from another class, you need form reference for this:

Dim dlg As New NoParamsDelagate(AddressOf form1.CloseConnect)   ' form1 is reference to form instance
form1.Invoke(dlg)

0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 600 total points
ID: 17783930
Hi TommyTwoPints;

If you are not calling the delegate from another thread then you can call it this way

    Dim dlg As New NoParamsDelagate(AddressOf CloseConnect)
    dlg()

...

    Private Sub CloseConnect()
        Console.WriteLine("Hello There I have been called")
    End Sub

Fernando
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17783947
Which is exactly equal to:
CloseConnect()
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17783960
Thanks everyone:)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question