@@ -82,28 +82,19 @@ void Disconnect()
82
82
{
83
83
btnToggle . Text = "Disconnecting..." ;
84
84
85
- ThreadPool . QueueUserWorkItem ( new WaitCallback ( ( state ) =>
86
- {
87
- portForwarded . Stop ( ) ;
88
- sshClient . Disconnect ( ) ;
89
- unset_windows_proxy ( ) ;
85
+ portForwarded . Stop ( ) ;
86
+ sshClient . Disconnect ( ) ;
87
+ unset_windows_proxy ( ) ;
90
88
91
- Invoke ( ( MethodInvoker ) delegate
92
- {
93
- btnToggle . Text = "Connect" ;
94
- lblStatus . BackColor = Color . Red ;
95
- lblStatus . Text = "Not Connected" ;
89
+ btnToggle . Text = "Connect" ;
90
+ lblStatus . BackColor = Color . Red ;
91
+ lblStatus . Text = "Not Connected" ;
96
92
97
- timer_check_status . Enabled = false ;
98
- timer_check_status . Stop ( ) ;
99
- seconds = 0 ;
100
-
101
- btnToggle . Enabled = true ;
102
- } ) ;
103
-
104
-
105
- } ) ) ;
93
+ timer_check_status . Enabled = false ;
94
+ timer_check_status . Stop ( ) ;
95
+ seconds = 0 ;
106
96
97
+ btnToggle . Enabled = true ;
107
98
}
108
99
109
100
@@ -118,7 +109,6 @@ private void btnToggle_Click(object sender, EventArgs e)
118
109
else Connect ( ) ;
119
110
120
111
Cursor . Current = Cursors . Default ;
121
-
122
112
}
123
113
124
114
@@ -130,15 +120,14 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
130
120
if ( result == DialogResult . No )
131
121
e . Cancel = true ;
132
122
else
133
- btnToggle_Click ( null , null ) ;
123
+ Disconnect ( ) ;
134
124
135
125
}
136
126
private void SystemEvents_SessionEnding ( object sender , SessionEndingEventArgs e )
137
127
{
138
128
if ( sshClient . IsConnected )
139
129
btnToggle_Click ( null , null ) ;
140
130
141
-
142
131
Application . Exit ( ) ;
143
132
}
144
133
@@ -148,15 +137,33 @@ private void btnOpenSettings_Click(object sender, EventArgs e)
148
137
settingsForm . ShowDialog ( ) ;
149
138
}
150
139
140
+ bool back_status = false ;
151
141
int seconds = 0 ;
152
142
private void timer_check_status_Tick ( object sender , EventArgs e )
153
143
{
154
- seconds ++ ;
144
+ if ( ! sshClient . IsConnected && sshClient . IsConnected != back_status )
145
+ {
146
+ Disconnect ( ) ;
147
+
148
+ notifyIcon1 . Icon = SystemIcons . Warning ;
149
+ notifyIcon1 . ShowBalloonTip ( 10 ) ;
150
+ }
151
+ else if ( sshClient . IsConnected && sshClient . IsConnected != back_status )
152
+ {
153
+ seconds = 0 ;
154
+ lblStatus . Text = "Connected 00:00:00" ;
155
+ }
156
+ else if ( sshClient . IsConnected )
157
+ {
158
+ seconds ++ ;
159
+
160
+ int hours = seconds / 3600 ;
161
+ int minutes = ( seconds % 3600 ) / 60 ;
162
+ int remainingSeconds = seconds % 60 ;
163
+ lblStatus . Text = "Connected " + hours . ToString ( "D2" ) + ":" + minutes . ToString ( "D2" ) + ":" + remainingSeconds . ToString ( "D2" ) ;
164
+ }
155
165
156
- int hours = seconds / 3600 ;
157
- int minutes = ( seconds % 3600 ) / 60 ;
158
- int remainingSeconds = seconds % 60 ;
159
- lblStatus . Text = "Connected " + hours . ToString ( "D2" ) + ":" + minutes . ToString ( "D2" ) + ":" + remainingSeconds . ToString ( "D2" ) ;
166
+ back_status = sshClient . IsConnected ;
160
167
}
161
168
162
169
private void set_windows_proxy ( )
0 commit comments