Saya memiliki fungsi yang membuat delegasi dan memulai BeginInvoke pada objek itu, dengan fungsi lain diteruskan untuk menunggu EndInvoke:
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);
}
Saya ingin menguji unit ini, tetapi ketika saya melakukannya, DeploymentComponentThreadedCallBack tidak pernah terkena, dan tentu saja panggilan EndInvoke juga tidak. Saya berasumsi ini terjadi karena pengujian berlalu sebelum thread asynchronous berakhir, sehingga thread berhenti dieksekusi sebelum EndInvoke, tetapi apakah ada cara agar saya dapat menghentikan hal ini sehingga saya dapat melihat bahwa EndInvoke terkena?
Salam, Mat