Using C# async method on c++

Viewed 1541

I made a class library (.net framework) project in C# and I want to use that DLL on my C++ client project.

I've checked on MSDN and online for instructions on how to I made it. So I could see C# code's result on my c++ project. except on C# async method.

A runtime error has occurred there.

This is parts of my C# dll code.

namespace NethereumDLLTest
{
    [Guid("1C3D53B3-54C5-452B-9505-3F58ABEB35BA")]
    public interface INethereumDLL
    {
        void Run();
    }

    [Guid("C22875F1-B74D-4C99-B446-ED705CE86D3B")]
    public class Class1 : INethereumDLL
    {

        //there are some methods here.

        public void Run()
        {
            Console.WriteLine("NethereumDLLTEST");

            RunGeth();

            Task task = new Task(ActionMethod);
            task.Start();
            Console.WriteLine("Main Logic");

            GetAccountBalance().Wait();
            Console.ReadLine();
        }

        static async Task GetAccountBalance()
        {
            for (int i = 10; i > 0; i--)
            {
                Thread.Sleep(1000);
            }
            var web3 = new Web3("http://localhost:8545");
            var balance = await  web3.Eth.GetBalance.SendRequestAsync("0xb3a11b62596b8b6313dddc30e9b11607c8f9fb38");

            Console.WriteLine($"Balance in Wei: {balance.Value}");
            var etherAmount = Web3.Convert.FromWei(balance.Value);
            Console.WriteLine($"Balance in Ether: {etherAmount}");
        }
    }
}

and here are cpp client's codes.

#import "C:\Users\june\source\repos\NethereumDLLTest\NethereumDLLTest\bin\Debug\NethereumDLLTest.tlb" 

using namespace std;
using namespace NethereumDLLTest;

int main()
{

    CoInitialize(NULL);

    {
        INethereumDLLPtr ptr(__uuidof(Class1));
        ptr->Run();
    }
    CoUninitialize();

}

I could find all log message above "GetAccountBalance" function, but it looks like it hasn't been executed after that.

Can't use C# async functions in c++? or Did I something wrong?

runtime error capture image

0 Answers
Related