I have a problem and don’t know where it is…
if I do this in a windows Form application:
private void btnListen_Click(...)
{
var t = new Thread(DoWork);
t.SetAppartmentState(ApartmentState.STA);
t.Start();
}
the DoWork method...
private void DoWork()
{
var controls = GetControls();
foreach (var c in controls)
{
control.OnEvent += HandleEvent;
}
}
private void HandleEvent()
{
DoSomething...
}
The controls are Wrapped Com objects registered with regsrv32
When firing events on controls, I don’t recive events in my Windows forms application HandleEvent method.
but if I change the code to this:
private void btnListen_Click(...)
{
DoWork();
}
the it works all ok.
I need this to be executed in another thread.
Why isn’t this working when using threads?
Please help.
thanks
EDIT:
I also tried this in a windows service.
Like this:
OnStart()
{
Task t = new Task(()=>DoWork);
t.Start();
}
every thing else is the same and still does not work. And there is no UI thread here.
the problem was the control driver (COM) dll that didn’t work. Installed new version and now it works.