Solved

invoking NoParamsDelagate within a class

Posted on 2006-10-22
5
246 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 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 63

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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