private static void CallBackCloseAlertForm(IAsyncResult ar) { //从C#异步调用状态ar.AsyncState中,获取委托对象 CloseAlertFormdelegate dn = (CloseAlertFormdelegate)ar.AsyncState; //一定要EndInvoke,否则你的下场很惨 dn.EndInvoke(ar); }
/// <summary> /// 关闭AlertForm /// </summary> /// <param name="frm"></param> public static void CloseAllAlertForm(Form frm) { if (frm.InvokeRequired) { CloseAlertFormdelegate outdelegate = new CloseAlertFormdelegate(CloseAllAlertForm); AsyncCallback acb = new AsyncCallback(CallBackCloseAlertForm); IAsyncResult iar = outdelegate.BeginInvoke(frm, acb, outdelegate); } else { frm.Close(); } }