Exemple #1
0
        void bgw_TransferFiles(object sender, DoWorkEventArgs e)
        {
            BgwArgs args = (BgwArgs)e.Argument;

            FileTransferConnection connection;

            // Setup connection
            if (radioClient.Checked)
            {
                connection = new Client(args.ip, args.port);
            }
            else
            {
                connection = new Server(args.port);
            }

            if (radioSend.Checked)
            {
                connection.FileList  = fileList;
                connection.NumFiles  = numFiles;
                connection.TotalSize = totalSize;

                connection.SendFiles((BackgroundWorker)sender);
            }
            else if (radioReceive.Checked)
            {
                connection.ReceiveFiles(args.path, (BackgroundWorker)sender);
            }
        }
Exemple #2
0
        void startTransfer()
        {
            string ip = IPTextBox.Text;
            int    port;

            if (!Int32.TryParse(portTextBox.Text, out port))
            {
                MessageBox.Show("Invalid port");
                return;
            }

            BgwArgs args = new BgwArgs(ip, port);

            if (radioReceive.Checked)
            {
                fileListView.Items.Clear();
                // Allow the user to select where to save the received files
                folderBrowser.ShowDialog();
                args.path = folderBrowser.SelectedPath;
                if (args.path == "")
                {
                    MessageBox.Show("Invalid save location");
                    return;
                }
            }

            DisableForm();

            bgw = new BackgroundWorker();
            bgw.WorkerReportsProgress      = true;
            bgw.WorkerSupportsCancellation = true;
            bgw.ProgressChanged           += bgw_ProgressChanged;
            bgw.DoWork             += bgw_TransferFiles;
            bgw.RunWorkerCompleted += bgw_TransferComplete;
            bgw.RunWorkerAsync(args);
        }