Skip to content

Commit

Permalink
moved text setting part to RunWorkerCompleted method in order to avoi…
Browse files Browse the repository at this point in the history
…d cross thread error
  • Loading branch information
handrake committed Sep 12, 2017
1 parent 708a089 commit 5fb885c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions PUBGAddon/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class Form1 : Form
private IPAddress localIP;
private IList<Tuple<String, List<Tuple<String, String>>>> serverList;
private BackgroundWorker packetCaptureWorker;
private Dictionary<IpV4Address, int> IPDict;

public Form1()
{
Expand Down Expand Up @@ -96,7 +97,7 @@ private Boolean IsIPInRange(String ip, String startRange, String endRange)

private void worker_DoWork(object sender, DoWorkEventArgs e)
{
Dictionary<IpV4Address, int> IPDict = new Dictionary<IpV4Address, int>();
IPDict = new Dictionary<IpV4Address, int>();

using (PacketCommunicator communicator = selectedDevice.Open(1024, PacketDeviceOpenAttributes.Promiscuous, 200))
{
Expand Down Expand Up @@ -135,13 +136,16 @@ private void worker_DoWork(object sender, DoWorkEventArgs e)
}
}
}
}

private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
textBox1.Text = "알 수 없음";

if (IPDict.Count() == 0)
{
textBox2.Text = "";
return;

goto End;
}

String mostCommonIP = IPDict.Aggregate((a, b) => a.Value > b.Value ? a : b).Key.ToString();
Expand All @@ -153,13 +157,12 @@ private void worker_DoWork(object sender, DoWorkEventArgs e)
if (serverList[i].Item2.Any(x => IsIPInRange(mostCommonIP.ToString(), x.Item1, x.Item2)))
{
textBox1.Text = serverList[i].Item1;
return;
goto End;
}
}
}

private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{

End:
button1.Enabled = true;
label3.Text = "";
this.ActiveControl = this.button1;
Expand Down

0 comments on commit 5fb885c

Please sign in to comment.