void PacketReceived(object sender, PacketReceivedEventArgs e) { var packet = new Packet(DateTime.Now, e.Address, e.Port, e.Contents); var packetViewModel = new PacketRowViewModel(packet); DispatcherHelper.CheckBeginInvokeOnUI(() => _packets.Add(packetViewModel)); if (_logWriter != null) { _logWriter.WriteLine("{0},\"{1}\",{2},\"{3}\"", packetViewModel.Timestamp, packetViewModel.Source, packetViewModel.Content.Length, packetViewModel.Content.Replace("\"", "\"\"")); } }