private static void Unhook(KeyBoardHook hook) { if (hook != null) { hook.UnHook(); GC.Collect(); } }
void Unhook() { if (KeyBoarHook != null) { KeyBoarHook.UnHook(); KeyBoarHook.OnKeyDownEvent -= KeyBoarHook_OnKeyDownEvent; GC.Collect();//增加GC防止窗体关闭后,钩子未被卸载. } }
/// <summary> /// 关闭,存储处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PipeAnnotationForm_FormClosing(object sender, FormClosingEventArgs e) { if (!CheckInputsOfSingle()) { return; } if (!CheckInputsOfMultiple()) { return; } if (!CheckInputsOfCommon()) { return; } //int lengthFromLine; //if (int.TryParse(tb_LengthFromLine.Text, out lengthFromLine)) //{ // PipeAnnotationCmd.PipeAnnotationUIData.SettingForSingle.LengthFromLine_Milimeter = lengthFromLine; //} //PipeAnnotationCmd.PipeAnnotationUIData.SettingForSingle.Location = rb_OnPipe.Checked ? SinglePipeTagLocation.OnPipe : SinglePipeTagLocation.AbovePipe; //PipeAnnotationCmd.PipeAnnotationUIData.SettingForSingle.NeedLeader = cb_Lead.Checked; ////Multiple //int lengthBetweenPipe; //if (int.TryParse(tb_LengthBetweenPipe.Text, out lengthBetweenPipe)) //{ // PipeAnnotationCmd.PipeAnnotationUIData.SettingForMultiple.LengthBetweenPipe_Milimeter = lengthBetweenPipe; //} //PipeAnnotationCmd.PipeAnnotationUIData.SettingForMultiple.Location = rb_OnLineEdge.Checked ? MultiPipeTagLocation.OnLineEdge : MultiPipeTagLocation.OnLine; //Common PipeAnnotationCmd.PipeAnnotationUIData.SettingForCommon.IncludeLinkPipe = cb_IncludeLinkPipe.Checked; PipeAnnotationCmd.PipeAnnotationUIData.SettingForCommon.AutoPreventCollision = cb_IsAutoPreventCollision.Checked; //0728长度过滤 if (KeyBoarHook != null) { KeyBoarHook.UnHook(); } }