PC Review


Reply
Thread Tools Rate Thread

BeginInvoke call another function

 
 
LP
Guest
Posts: n/a
 
      18th Mar 2005
Hi,

I have a method that's called from another thread through a delegate. It's
checking if (InvokeRequired){} and does BeginInvoke() if true. So it will be
executed on the same UI thread. here's the code in question:

private void wrkP_OnProcessCompleted(WorkerProcessBalanceEventArgs e)
{
if (InvokeRequired)
{
BeginInvoke(new delegateUpdateProgress(wrkP_OnProcessCompleted), new
object[] {e});
return;
}
anotherPrivateFunction();
//more code here
}

Question do I need a delegate for anotherPrivateFunction(); or it will
be executed by UI thread anyway?


 
Reply With Quote
 
 
 
 
Ajay Kalra
Guest
Posts: n/a
 
      18th Mar 2005
anotherPrivateFunction is simply another call to the function. You dont
need any delegate declaration for it. If anotherPrivateFunction alters
controls on the form, it will/should do what you have done here, use
InvokeRequired.

---------
Ajay Kalra
(E-Mail Removed)

 
Reply With Quote
 
LP
Guest
Posts: n/a
 
      18th Mar 2005
>>If anotherPrivateFunction alters controls on the form

Yes, it does.

>>it will/should do what you have done here, use InvokeRequired. use

InvokeRequired.

You are saying it will use Delegate or I need to program it?


I


"Ajay Kalra" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> anotherPrivateFunction is simply another call to the function. You dont
> need any delegate declaration for it. If anotherPrivateFunction alters
> controls on the form, it will/should do what you have done here, use
> InvokeRequired.
>
> ---------
> Ajay Kalra
> (E-Mail Removed)
>



 
Reply With Quote
 
Ajay Kalra
Guest
Posts: n/a
 
      18th Mar 2005
anotherPrivateFunction will look similar to wrkP_OnProcessCompleted.
You will check InvokeRequired and then you will instatiate a new
delegate object to call itself. Something like ths:

1. // Declare delegatAnotherPrivateFunction in your class

2. Function can be something like this:

private void anotherPrivateFunction(object obj)
{
if (InvokeRequired)
{
BeginInvoke(new
delegatAnotherPrivateFunction(anotherPrivateFunction), new ..);
return;
}
....
}

---------
Ajay Kalra
(E-Mail Removed)

 
Reply With Quote
 
Daniel Pratt
Guest
Posts: n/a
 
      18th Mar 2005
Hi LP,

"LP" <(E-Mail Removed)> wrote in message
news:OVt$(E-Mail Removed)...
> Hi,
>
> I have a method that's called from another thread through a delegate. It's
> checking if (InvokeRequired){} and does BeginInvoke() if true. So it will
> be
> executed on the same UI thread. here's the code in question:
>
> private void wrkP_OnProcessCompleted(WorkerProcessBalanceEventArgs e)
> {
> if (InvokeRequired)
> {
> BeginInvoke(new delegateUpdateProgress(wrkP_OnProcessCompleted), new
> object[] {e});
> return;
> }
> anotherPrivateFunction();
> //more code here
> }
>
> Question do I need a delegate for anotherPrivateFunction(); or it will
> be executed by UI thread anyway?


What you have will work fine. You do not need to create a separate
delegate for anotherPrivateFunction().

Regards,
Daniel


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call BeginInvoke for a sub that has a parameter ? fniles Microsoft VB .NET 3 6th Jun 2006 01:36 AM
Control.BeginInvoke vs. delegate.BeginInvoke Valerie Hough Microsoft C# .NET 6 21st Oct 2005 11:14 AM
Issue w Interop Code uses Asynchronous Call(BeginInvoke and EndInv =?Utf-8?B?SCBXdQ==?= Microsoft Dot NET 0 29th Dec 2004 04:13 PM
Can I call BeginInvoke without ever calling EndInvoke? babylon Microsoft Dot NET Framework 1 23rd Mar 2004 09:39 AM
Call BeginInvoke on a Delegate Thomas Lerchner Microsoft Dot NET Compact Framework 1 10th Sep 2003 01:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:04 AM.