시스템 트레이 아이콘에서 실행중인 단일 Windows 양식 응용 프로그램이 있습니다. 사용자가 X 단추를 누르면 메시지 상자가 예 및 아니오 (예)로 표시됩니다. -> 양식을 닫으십시오 - 아니오 -> 시스템 트레이 아이콘에서 양식을 계속 실행하십시오. 나는 사용자가 응용 프로그램의 다른 인스턴스를 열 때 나는이 코드를 사용하고 있으므로 실행중인 인스턴스가 이미있을 때 시나리오를 방지하기 위해 생각했다 :Application.Exit() 및 Vb.net FormClosing 이벤트
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length> 1 Then
MessageBox.Show("Another instance is running", "Error Window", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Application.Exit()
End If
문제는 그 나는이 메시지를 테스트 할 때 표시되지만 확인을 누르면 새 메시지 상자가 나타납니다 (Private Sub Form_FormClosing의 해당 메시지 상자). 아니오를 선택하면 인스턴스를 실행해야합니다! Application.Exit이 Form_FormClosing 이벤트를 발생시키는 것을 읽었습니다.
Form_FormClosing 이벤트의 트리거링을 취소 할 가능성이 있습니까? 아니면 잘못된 것이 있습니까?
'이것은 formclosing 절차를
Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
Dim response As MsgBoxResult
response = MsgBox("Are you sure you want to exit", CType(MsgBoxStyle.Question + MsgBoxStyle.YesNo, MsgBoxStyle), "Confirm")
'If the user press Yes the application wil close
'because the application remains in taskmanager after closing i decide to kill the current process
If response = MsgBoxResult.Yes Then
Process.GetCurrentProcess().Kill()
ElseIf response = MsgBoxResult.No Then
e.Cancel = True
Me.WindowState = FormWindowState.Minimized
Me.Hide()
NotifyIcon1.Visible = True
End If
PS입니다 : 내가 아닌 프로그래머가 그렇게 나와 함께 가혹한로하지 마십시오 :) 상황에서
답변을 주셔서 감사합니다 ... 나는이 방법을 사용하여 확인해야합니다 비주얼 스튜디오 속성에서 설정을 발견했습니다 ...unfortunatelly 나는 왜 내 응용 프로그램이 종료 후 작업 관리자에서 종료되지 않는지 관리하지 못했습니다 ... 그것이 왜이 임시 솔루션을 찾았는지 .... 기본적으로 응용 프로그램은 간단한 Windows 양식입니다. – Operagust