Search code examples
c#multithreadingawesomium

Awesomium multithreading c#?


So I'm trying to figure out a way to run 2 or more processes of Webview at the same time? I saw that I could accomplish this with multithreading but Awesomium dosen't support this and it just gives me an error:

Awesomium.Core.AweInvalidOperationException: 'The calling thread cannot access this object because a different thread owns it.'

How can I do this?

my code:

first class:

secondclass sclass = new secondclass();
Thread nakedCPH = new Thread(() => sclass.run(name));
nakedCPH.Start();

second class:

internal ThreadStart runNakedCPH(string v)
{
    MessageBox.Show(v);
    throw new NotImplementedException();
}

Solution

  • Try this:

    Thread nakedCPH = new Thread(() =>
    {
        secondclass sclass = new secondclass();
        sclass.run(name);
    });
    nakedCPH.Start();
    

    The problem you'll get is if the MessageBox.Show(v); is running on this new thread. It'll fail because you can only call UI functions on the UI-thread.