Solved

invoking NoParamsDelagate within a class

Posted on 2006-10-22
5
245 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
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 250 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 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 150 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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