Skip to content

Commit 80e96f5

Browse files
Support to monitor all the network interface at the same time
1. Support to monitor all the network interface at the same time 2. Upgrade the .Net framework from v4.6.1 to v4.8 3. Minor update
1 parent beb9f2a commit 80e96f5

File tree

8 files changed

+81
-43
lines changed

8 files changed

+81
-43
lines changed

CommonSet.cs

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ public bool CheckIfRunning(String programName)
9797

9898
public bool CheckIfRunningSameProcess(String programName)
9999
{
100-
Process[] processes = Process.GetProcessesByName(programName);
101-
// check if there any program running with same name
102-
if (processes.Length > 1)
103-
{
104-
return true;
105-
}
106-
return false;
100+
// check if there any program running with same name under the current user
101+
var currentSessionID = Process.GetCurrentProcess().SessionId;
102+
Process[] processes = Process.GetProcessesByName(programName).Where(p => p.SessionId == currentSessionID).ToArray();
103+
104+
return processes.Length > 1;
107105
}
108106

109107
public bool CheckIfNameChanged(String programName)
@@ -219,38 +217,54 @@ public void EndAllProcess()
219217
{
220218
// close all the related application
221219
// check if floating window is opened, if yes close all the floating window
220+
var currentSessionID = Process.GetCurrentProcess().SessionId;
222221
Process[] processes = Process.GetProcessesByName(floatingWindowProcessName);
223222
foreach (var process in processes)
224223
{
225-
process.Kill();
224+
if(process.SessionId == currentSessionID)
225+
{
226+
process.Kill();
227+
}
226228
}
227229

228230
// check if configuration window is opened, if yes close all the floating window
229231
processes = Process.GetProcessesByName(configurationProcessName);
230232
foreach (var process in processes)
231233
{
232-
process.Kill();
234+
if (process.SessionId == currentSessionID)
235+
{
236+
process.Kill();
237+
}
233238
}
234239

235240
// close booter
236241
processes = Process.GetProcessesByName(booterProgramProcessName);
237242
foreach (var process in processes)
238243
{
239-
process.Kill();
244+
if (process.SessionId == currentSessionID)
245+
{
246+
process.Kill();
247+
}
240248
}
241249

242250
// close this application
243251
processes = Process.GetProcessesByName(baseProgramProcessName);
244252
foreach (var process in processes)
245253
{
246-
process.Kill();
254+
if (process.SessionId == currentSessionID)
255+
{
256+
process.Kill();
257+
}
247258
}
248-
249-
250259
}
251260

252261
public int GetInterfaceIndexWithName(string interfaceName)
253262
{
263+
if(interfaceName == "全部" || interfaceName == "All")
264+
{
265+
return 0;
266+
}
267+
254268
for (int i = 0; i < interfaces.Length; i++)
255269
{
256270
if (interfaces[i].Name.Equals(interfaceName))
@@ -269,8 +283,25 @@ public void GetTrafficInformation(int SpeedUnitSelectedIndex, int selectedInterf
269283
/*Task.Factory.StartNew(() =>
270284
{*/
271285
double divisionParameter = 1.0;
272-
long uploadTrafficValueTemp = interfaces[selectedInterfaceIndex].GetIPv4Statistics().BytesSent;
273-
long downloadTrafficValueTemp = interfaces[selectedInterfaceIndex].GetIPv4Statistics().BytesReceived;
286+
287+
long uploadTrafficValueTemp = 0;
288+
long downloadTrafficValueTemp = 0;
289+
290+
if (selectedInterfaceIndex == 0)
291+
{
292+
// get the traffic value for all the network interface if the selected interface index is 0
293+
foreach(NetworkInterface networkInterface in interfaces)
294+
{
295+
uploadTrafficValueTemp += networkInterface.GetIPv4Statistics().BytesSent;
296+
downloadTrafficValueTemp += networkInterface.GetIPv4Statistics().BytesReceived;
297+
}
298+
}
299+
else
300+
{
301+
uploadTrafficValueTemp = interfaces[selectedInterfaceIndex].GetIPv4Statistics().BytesSent;
302+
downloadTrafficValueTemp = interfaces[selectedInterfaceIndex].GetIPv4Statistics().BytesReceived;
303+
}
304+
274305

275306
// get the value corrseponding to the selected speed
276307
uploadTrafficValue = uploadTrafficValueTemp - previousUploadValue;

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ A lgihtweight and easy-to-use network monitor
99

1010
# Reminder
1111
1. For Windows only
12-
2. This project is developed base on .NET Framework 4.6.1. If your cannnot use this tool, please try to update your .NET Framework.
13-
3. Certain anti-virus programs are known to throw false positive-results. We are still investigating this issue and in the mean time, please rest assured that SNTM is completely safe.
12+
2. This project is developed base on .NET Framework 4.8. If your cannnot use this tool, please try to update your .NET Framework.
13+
3. Certain anti-virus programs are known to throw false positive-results. We are not putting any malicious code in the program and we still investigating this issue.
1414
4. For the sake of saving the configuration files, please do not put this software to the folder that need administrator permission.
1515

1616
# Icons used

SNTMConfiguration/MainWindow.xaml.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public partial class MainWindow : Window
9393
CommonSet commonSet = new CommonSet();
9494

9595
// variables for record the selected index
96+
int NetworkInterfaceIndexTemp;
9697
int DisplayIndexTemp;
9798
int SizeIndexTemp;
9899
int ThemeIndexTemp;
@@ -123,22 +124,6 @@ public MainWindow()
123124
this.Close();
124125
}
125126

126-
// check if any same process running, if yes, close all of them
127-
if (commonSet.CheckIfRunningSameProcess(commonSet.configurationProcessName))
128-
{
129-
// *** removed
130-
/*if (this.LanguageSelectionBox.SelectedIndex == 1)
131-
{
132-
MessageBox.Show("配置視窗已開啟。");
133-
}
134-
else
135-
{
136-
MessageBox.Show("Configuration Window is opened already.");
137-
}*/
138-
MessageBox.Show("Configuration Window is opened already.");
139-
this.Close();
140-
}
141-
142127
// check if the program name is changed
143128
if (commonSet.CheckIfNameChanged(commonSet.configurationProcessName))
144129
{
@@ -219,6 +204,20 @@ private void GetInterfaceInformation()
219204
return;
220205
}
221206

207+
// the first option is monitor all the network interface
208+
if (this.LanguageSelectionBox.SelectedIndex == 1)
209+
{
210+
this.NetworkInterfaceSelectionBox.Items.Add("全部");
211+
}
212+
else if (this.LanguageSelectionBox.SelectedIndex == 2)
213+
{
214+
this.NetworkInterfaceSelectionBox.Items.Add("全部");
215+
}
216+
else
217+
{
218+
this.NetworkInterfaceSelectionBox.Items.Add("All");
219+
}
220+
222221
// get the list of network interface
223222
interfaces = NetworkInterface.GetAllNetworkInterfaces();
224223

@@ -616,7 +615,7 @@ private void ResetButton_Click(object sender, RoutedEventArgs e)
616615
}
617616
else
618617
{
619-
MessageBox.Show("Configuration is resetted to the status when the program is started.");
618+
MessageBox.Show("Configuration is resetted to the status when this window is opened.");
620619
}
621620
}
622621
else
@@ -677,8 +676,8 @@ private void DefaultButton_Click(object sender, RoutedEventArgs e)
677676
// reset the network interface
678677
this.NetworkInterfaceSelectionBox.SelectedIndex = 0;
679678

680-
// reset the update frequency to 1 second
681-
this.UpdateFrequencySlider.Value = 1;
679+
// reset the update frequency to 0.5 second
680+
this.UpdateFrequencySlider.Value = 0.5;
682681

683682
// reset the speed unit to MB/s
684683
this.SpeedUnitSelectionBox.SelectedIndex = 3;
@@ -719,6 +718,7 @@ private void DefaultButton_Click(object sender, RoutedEventArgs e)
719718
public void changeLanguages()
720719
{
721720
// save the selected index
721+
NetworkInterfaceIndexTemp = this.NetworkInterfaceSelectionBox.SelectedIndex;
722722
DisplayIndexTemp = this.DisplaySelectionBox.SelectedIndex;
723723
SizeIndexTemp = this.WindowSizeSelectionBox.SelectedIndex;
724724
ThemeIndexTemp = this.DarkThemeSelectionBox.SelectedIndex;
@@ -762,6 +762,8 @@ public void changeLanguages()
762762

763763
this.ShowBubbleCheckBox.Content = "顯示提示訊息";
764764

765+
this.NetworkInterfaceSelectionBox.Items[0] = "全部";
766+
765767
}
766768
else if (this.LanguageSelectionBox.SelectedIndex == 2)
767769
{
@@ -805,6 +807,7 @@ public void changeLanguages()
805807
// ****
806808
this.ShowBubbleCheckBox.Content = "通知メッセージを表示する";
807809

810+
this.NetworkInterfaceSelectionBox.Items[0] = "全部";
808811
}
809812
else
810813
{
@@ -844,9 +847,12 @@ public void changeLanguages()
844847
this.DarkThemeSelectionBox.Items[1] = "On";
845848

846849
this.ShowBubbleCheckBox.Content = "Show bubble message";
850+
851+
this.NetworkInterfaceSelectionBox.Items[0] = "All";
847852
}
848853

849854
// restore the selected index
855+
this.NetworkInterfaceSelectionBox.SelectedIndex = NetworkInterfaceIndexTemp;
850856
this.DisplaySelectionBox.SelectedIndex = DisplayIndexTemp;
851857
this.WindowSizeSelectionBox.SelectedIndex = SizeIndexTemp;
852858
this.DarkThemeSelectionBox.SelectedIndex = ThemeIndexTemp;

SNTMStartProcess/About.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace SNTMStartProcess
3939
{
4040
public partial class About : Form
4141
{
42-
string version = "v1.2.2.0";
42+
string version = "v1.2.3.0";
4343
CommonSet commonSet = new CommonSet();
4444
public About()
4545
{

booter/App.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
55
</startup>
6-
</configuration>
6+
</configuration>

booter/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

booter/Properties/Settings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

booter/SNTMBooter.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
<OutputType>WinExe</OutputType>
99
<RootNamespace>SNTMBooter</RootNamespace>
1010
<AssemblyName>SNTMBooter</AssemblyName>
11-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1414
<Deterministic>true</Deterministic>
15+
<TargetFrameworkProfile />
1516
</PropertyGroup>
1617
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1718
<PlatformTarget>AnyCPU</PlatformTarget>

0 commit comments

Comments
 (0)