SuRGeoNix / Flyleaf

Media Player .NET Library for WinUI 3/ WPF/WinForms (based on FFmpeg/DirectX)
GNU Lesser General Public License v3.0
715 stars 101 forks source link

InvalidOperationException on program start #219

Closed minisbett closed 1 year ago

minisbett commented 1 year ago

.NET 7, newest nuget version, WinForms

Running the Engine start code from the wiki in the Program.Main method, in the constructor of the Form I have the code

FlyleafLib.Config config = new FlyleafLib.Config();
config.Video.BackgroundColor = Colors.Black;
flyleafHost.Player = new Player(config);

On the last line, I get an InvalidOperationException that tells me the current thread is not in STA mode. I already tried putting the above code in a method and putting the [STAThread] attribute there without success. Any ideas?

minisbett commented 1 year ago

Oh I should mention the STAThread exception is just the inner exception, the actual exception tells me that DragDrop could not be registered image It's german but maybe it helps

minisbett commented 1 year ago

Apparently the problem also exists if I just put the flyleaf host on the form, without creating any Player object or starting the engine

SuRGeoNix commented 1 year ago

Hi @minisbett, I tried to create a new .NET 7 WinForms project and add FlyleafHost from toolbox to the form and everything was working fine. Are you doing something different because it does not make sense. From the error message that you share it seems that you initialize the Form1 from another thread.

You probably use async somewhere eg (restore that to void) :-

[STAThread]
static async Task Main()
{
}
minisbett commented 1 year ago

Oh well that might be the problem, my Main function is async. But I can't change that, it has to be. That shouldn't be a problem when using your library tho.

SuRGeoNix commented 1 year ago

Calling InitializeComponent() from non UI thread sounds like an issue for your design and not my library's

minisbett commented 1 year ago

Well everything works except for your library. I feel like there's more something that should be handled differently in your library since an async entry point is very common nowadays

SuRGeoNix commented 1 year ago

Well everything crashes if you enable AllowDrop initially still not my issue

minisbett commented 1 year ago

I tried disabling AllowDrop but it didn't change anything

SuRGeoNix commented 1 year ago

By default the library sets this in the constructor to true