calling a C# method asynchronously from VB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all
I am trying to call a C# method (in a DLL) asynchronously from VB. I don't
know how to do this. Any suggestion is appreciated. Thanks.
 
Lak said:
I am trying to call a C# method (in a DLL) asynchronously from VB. I don't
know how to do this. Any suggestion is appreciated. Thanks.

Do you mean VB6 or VB.NET?

Jon
 
Lak said:

Ah. That makes life a bit harder - and I can't help you. I suggest you
wait a while for answers in this group, and if nothing helpful comes
along, try asking again in the .interop group.

Jon
 
Please define what you mean with 'asynchronously', your only option to call
into C# is through COM interop and such method calls are always synchronous.

What exactly are you trying to achieve?

Willy.




| VB6.0
|
| "Jon Skeet [C# MVP]" wrote:
|
| > Lak wrote:
| > > I am trying to call a C# method (in a DLL) asynchronously from VB. I
don't
| > > know how to do this. Any suggestion is appreciated. Thanks.
| >
| > Do you mean VB6 or VB.NET?
| >
| > Jon
| >
| >
 
I have a C# method that will run for a while. While it runs, I don't want to
lock up the GUI. I need to retrieve some progress information from the C#
DLL. Therefore, I want to run the first method asynchronous so that I can use
another method to retrieve progress info. Does this help? Thanks for your
reply.
 
Lak,

The problem with this involves the threading model that is inherent to
VB.

While you could start an asynchronous operation in VB (calling a .NET
component) and then provide some sort of callback, the problem is that you
have to call back on the thread that the component was created on. This
presents a problem.

The easiest way to do this would be to create an interface that
represents the callback which your VB component will implement. You then
pass this interface in a call to start the asynchronous operation. You can
then pass this interface to your thread, which will call back on the
interface.

The only problem here is that you have to marshal the interface
correctly, using the global interface table. You can do this using the
IGlobalInterfaceTable interface (through COM interop), or the
CoMarshalInterThreadInterfaceInStream function.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lak said:
I have a C# method that will run for a while. While it runs, I don't want
to
lock up the GUI. I need to retrieve some progress information from the C#
DLL. Therefore, I want to run the first method asynchronous so that I can
use
another method to retrieve progress info. Does this help? Thanks for your
reply.

Willy Denoyette said:
Please define what you mean with 'asynchronously', your only option to
call
into C# is through COM interop and such method calls are always
synchronous.

What exactly are you trying to achieve?

Willy.




| VB6.0
|
| "Jon Skeet [C# MVP]" wrote:
|
| > Lak wrote:
| > > I am trying to call a C# method (in a DLL) asynchronously from VB.
I
don't
| > > know how to do this. Any suggestion is appreciated. Thanks.
| >
| > Do you mean VB6 or VB.NET?
| >
| > Jon
| >
| >
 
Back
Top