private void SaveButton_Click(object sender, System.Windows.RoutedEventArgs e) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "F1 Profiler files (*.prof)|*.prof"; dlg.Title = "Where should I save profiler results?"; if (dlg.ShowDialog() == true) { lock (frames) { FileStream stream = new FileStream(dlg.FileName, FileMode.Create); frames.Serialize(stream); stream.Close(); } } }
static void Main(string[] args) { var options = new Options(); if (!CommandLine.Parser.Default.ParseArguments(args, options)) { return; } IPAddress ip = null; IPAddress.TryParse(options.IpAddress, out ip); ProfilerClient.Get().IpAddress = ip; ProfilerClient.Get().Port = options.Port; // Receive thread Thread socketThread = new Thread(RecieveMessage); socketThread.Start(); var connectionEstablished = false; do { System.Console.WriteLine("Trying to connect..."); connectionEstablished = ProfilerClient.Get().CheckConnection(100); if (connectionEstablished) { System.Console.WriteLine("Connected sucessfully."); } else { System.Threading.Thread.Sleep(500); } }while (!connectionEstablished); // Begin profiling if (ProfilerClient.Get().SendMessage(new StartMessage())) { System.Console.WriteLine("Begin capturing..."); while (true) { // Wait until a packet was done Thread.Sleep(1000); // Lost connection -> exit if (!ProfilerClient.Get().IsConnected) { break; } // Emulate a message dump ProfilerClient.Get().SendMessage(new StopMessage()); ProfilerClient.Get().SendMessage(new StartMessage()); } System.Console.WriteLine("Done capturing."); socketThread.Abort(); socketThread = null; // Connection was closed, save the data FileStream stream = new FileStream(options.Output, FileMode.Create); frames.Serialize(stream); } // Close the connection ProfilerClient.Get().Close(); }