4

How to get the value of a returned value from an async from an external function in PowerBuilder? I made a simple example in VB2013 .NET 4.5 and compiled it as a DLL. And inside the DLL is an async method like so:

test.DLL

    public async Task<string> GetTestAsync()
    {
        Task<string> task = GetTest();

        string test = await task;

        return test;
    }

    public async Task<string> GetTest()
    {
        string test;
        test = "TEST";

        return test;
    }

and I have called the DLL in PowerBuilder like so:

String test
test = String(myoleobject.GetPortsTestAsync())

if isnull(test) then
   messagebox('', 'null value')
end if

The result always returns a null value.

I've also tried this one, but it still returns a null value.

    public Task<string> GetTestAsync()
    {
        return Task.Factory.StartNew(() =>
        {
            return "hello";
        });
    }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dac
  • 210
  • 3
  • 19

2 Answers2

0

You'll need to perform a callback from your DLL to PowerBuilder.

I assume that because you call a method of "myoleobject" that you are using oleobject.

If that is the case, here is something to try.


In VB

  • Create an OLE event
  • Set the value
  • Trigger the event

In PowerBuilder

  • Inherit an OLEOBJECT
  • Create an event that corresponds to the VB OLE event
  • Get the value.
Eric Glenn
  • 389
  • 2
  • 12
-1

You might need to get creative here, the only thing that jumps out at me is to set a property in your VB control that informs your PB application that a value is ready. The problem is that you are forced to poll the VB application constantly.

Another option is to hold-up PB when the function is called in VB, but it totally defeats the purpose of an async function. Wish I could help more been a while since I've done anything like this.

Rich Bianco
  • 4,141
  • 3
  • 29
  • 48