We try to automate test over some old legacy code. There is a form which opens, run the timer and read data from port. The unittest open the form, but the timer does not tick until Application.DoEvents start process the process the windows message queue. It is different because it is execute from unittest and Application.Run is not the part of code.
But we cannot block unittest thread by Application.DoEvents, because we need to wait and check data by assert.
ThreadPool.QueueUserWorkItem(x =>
{
While(!form.workFinished)
{
Application.DoEvents();
Thread.Sleep(50);
}
synchronization.Set();
});
synchronization.WaitOne();
Assert.AreEqual(10000, form.recorded.Count);
But this snippet is not doing what I would expect. It is different than executing the form from WinForm App? Can I call Application.DoEvents from threadpool?
I really don't want really not modify the legacy code. I just need to get unittest working over current solution.