Solved

invoking NoParamsDelagate within a class

Posted on 2006-10-22
5
241 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
5 Comments
 
LVL 10

Assisted Solution

by:Kinger247
Kinger247 earned 100 total points
Comment Utility
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 250 total points
Comment Utility
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 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 150 total points
Comment Utility
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
Comment Utility
Which is exactly equal to:
CloseConnect()
0
 
LVL 3

Author Comment

by:TommyTwoPints
Comment Utility
Thanks everyone:)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now