/// <summary> /// Start the transfer /// </summary> public void StartTransfer() { //------------------------------------ // Wake up the transfer thread //------------------------------------ lock (this) { Status = Reply.ACCEPTED; Monitor.Pulse(this); } //------------------------------------ // Re-activate the Transfers Window //------------------------------------ // NOTE: Apparently, t.Show() or/with t.Activate() do not re-activate it. TransfersWindow t = (TransfersWindow)Application.Current.Properties["TransfersWindow"]; t.WindowState = WindowState.Normal; t.Topmost = true; t.Show(); t.Activate(); t.Topmost = false; // Now you can actually close this window TheWindow.Close(); }
/// <summary> /// Start sending the transfer request /// </summary> /// <param name="users">Array of selected users to send the file to</param> public void StartSending(User[] users) { //------------------------------------ // Add this to current transfers //------------------------------------ List <Task> Transfers = (List <Task>)Application.Current.Properties["Transfers"]; // Send a request for each user selected foreach (User u in users) { Transfers.Add(Task.Run(() => { Send s = new Send(ClickedPath, u); s.Start(); })); } //------------------------------------ // Re-activate the Transfers Window //------------------------------------ // NOTE: Apparently, t.Show() or/with t.Activate() do not re-activate it. TransfersWindow t = (TransfersWindow)Application.Current.Properties["TransfersWindow"]; t.WindowState = WindowState.Normal; t.Topmost = true; t.Show(); t.Activate(); t.Topmost = false; // Close current window SendWindow.Close(); }
/// <summary> /// App Constructor /// </summary> App() { //------------------------------------ // Application-wide properties //------------------------------------ // Denotes that the app is exiting, used to notify that we are exiting *NOT* going to taskbar Application.Current.Properties["Exiting"] = false; // The cancellation token and source Application.Current.Properties["MainCancellationSource"] = Source; Token = Source.Token; Application.Current.Properties["MainCancellationToken"] = Token; // Settings // NOTE: I discovered the C# Application.Settings.Default when I was too far in programming. // On next project, I'll be using that instead. Application.Current.Properties["Settings"] = new Settings(); // The Main window MainWindow mainWindow = new MainWindow(); //------------------------------------ // Set up taskbar icon //------------------------------------ TaskbarIcon = new System.Windows.Forms.NotifyIcon(); TaskbarIcon.DoubleClick += (s, args) => mainWindow.ShowMainWindow(); TaskbarIcon.Icon = FileShare.Properties.Resources.ShareIcon; TaskbarIcon.Visible = true; //------------------------------------ // Background workers //------------------------------------ // Note: Tasks will be waited later, right now they are in (almost) infinite loop, // They just keep running until the app cancels them by calling MainCancellationTokenSource.Token.Cancel(). MulticastWorker = Task.Run(() => { MulticastManager mm = new MulticastManager(); }); SendToWorker = Task.Run(() => { SendtoListener s = new SendtoListener(); s.Listen(); }); ConnectionsListenerWorker = Task.Run(() => { ConnectionsListener c = new ConnectionsListener(); c.Start(); }); //------------------------------------ // The Transfers Window //------------------------------------ // The transferrers Application.Current.Properties["Transfers"] = new List <Task>(); // The list of progress bars Application.Current.Properties["TransferProgresses"] = new ObservableCollection <TransferProgress>(); // The Users // NOTE: it's an ObservableCollection, so that when you want to send a file to someone, // new users will be added triggering CollectionChanged event and showing them on the window. Application.Current.Properties["Users"] = new ObservableCollection <User>(); // Finally, start the Transfers Window and propagate it to everyone, // so that they can show the window when a new connection is to be made. TransfersWindow t = new TransfersWindow(); Application.Current.Properties["TransfersWindow"] = t; }