ฉันมีฟังก์ชันที่สร้างการมอบหมายและเริ่ม BeginInrigg บนวัตถุนั้น โดยมีฟังก์ชันอื่นถูกส่งผ่านไปเพื่อรอ EndInrigg:
private static void DeploymentComponentThreadedCallBack(IAsyncResult ar)
{
var result = (AsyncResult)ar;
var pluginExecuteAction = (Action<int, Guid, int, EnvironmentServerComponentSet, string>)result.AsyncDelegate;
pluginExecuteAction.EndInvoke(ar);
//report back to WCF service that thread is finished
}
public void DeployComponent(byte[] resource, Guid componentGuid, string deploymentType, Dictionary<string, object> args)
{
var asyncCallback = new AsyncCallback(DeploymentComponentThreadedCallBack);
IDeployComponent plugin = GetPluginDelegate();
Action<byte[], Guid, string, Dictionary<string, object>> pluginExecuteAction = plugin.DeployComponent;
IAsyncResult ar = pluginExecuteAction.BeginInvoke(resource, componentGuid, deploymentType, args, asyncCallback, null);
}
ฉันต้องการทดสอบหน่วยนี้ แต่เมื่อทำเช่นนั้น DeploymentComponentThreadedCallBack จะไม่โดนโจมตี และเห็นได้ชัดว่า EndInrigg ไม่มีการเรียกเช่นกัน ฉันคิดว่าสิ่งนี้เกิดขึ้นเนื่องจากการทดสอบผ่านไปก่อนที่เธรดแบบอะซิงโครนัสจะสิ้นสุด ดังนั้นเธรดจึงหยุดดำเนินการก่อน EndInrigg แต่มีวิธีที่ฉันสามารถหยุดสิ่งนี้เกิดขึ้นเพื่อที่ฉันจะได้เห็นว่า EndInrigg ได้รับผลกระทบหรือไม่
ไชโยแมตต์