Blocking calls but do not block thread
Recently I came across a proprietary third-party library and there is a
method behave in this way:
public Point ClickOnDrawMat(DrawMat drwmat)
{
Point pt;
//waiting user mouse click on DrawMat and assign to pt
return pt;
}
When my code calling this method from main thread, it will block on this
method until user clicks, then get the point return from ClickOnDrawMat.
public void button1_Click(object sender, EventArgs e)
{
Point userClickedPoint = ClickOnDrawMat(oDrwMat); //Wait until user
clicked
//Do stuff with point we got
}
However, it doesn't block the main thread. I still can press other
button/UI control while it is still waiting for user click.
I noticed that upon waiting for user click, one of the CPU core usage
seems pretty high (~75%).
And this is an example of the call stack after I click on another button
while it still waiting for user click:
myProgram.frmMain.button2_Click(xxx) Line 23
[External Code]
ThirdPartyLib.ClickOnDrawMat(xxx) Line 16
myProgram.frmMain.button1_Click(xxx) Line 14
I am wondering how can this be done?
Thanks in advance!
No comments:
Post a Comment