c# - Forms created from async void Form.Load event handler of another Form -
i have async void event handler creates , form , passes sempahoreslim initial count 0 , waits asyncronously on (showing form before wait). when click button in form semaphore released , event handler continues execution on same context (uithread). debugging found when form shown , defwndproc called (called internally .net framework form class implementation) application freezes. why?
class debugform : form { semaphoreslim waitok; public debugform (semaphoreslim waitok) { initializecomponent(); this.waitok = waitok; } //added in initializecomponent async void buttonok_click(object sender, eventargs e) { //do stuff ui waitok.release(); } }
in mainform load event this:
async void mainform_load(object sender, eventargs e) { semaphoreslim sem = new semaphoreslim(0); form debugform = new debugform(sem); //it stucks in show call low probability debugform.show(); await sem.waitasync(); //do other stuff }
Comments
Post a Comment