How to make asynchronous call ?

  • Thread starter Thread starter Laurent
  • Start date Start date
L

Laurent

Hi all,

First, I use C# with the .NET Framework 2.0.

I would like in the method OnButtonClick, call the method A.DoSomething but
in a way that executes after
OnButtonClick has finished its execution.
I am looking for something like a PostMessage in Win32 in fact.
How can I do that in C# ?


Class A
{
// may be inheriting from Form too
void DoSomething() { }
}

Class B : Form
{
void OnButtonClick() // for example
{
// call A.DoSomething but do not execute yet

return;
// now it is the time that DoSomething must execute
}
}


Thank,
Laurent
 
I'm more a VB.NET programmer, so I cannot give youC# source code, but you
could gave a look at delegates and the "BeginInvoke" method that you can use
to start a method on a background thread and continuing your main thread in
the meantime.

If you want it to only start executing when you calling method has finished,
then you probably need to put the method call to BeginInvoke as the last
statement before the "return" statement in your example.

Hope this helps,

Joris
 
Back
Top