?
Solved

invoking NoParamsDelagate within a class

Posted on 2006-10-22
5
Medium Priority
?
248 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 63

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

752 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