コード例 #1
0
        public void LibraryBuildCompleteCallback(IAsyncResult ar)
        {
            var  buildState = (LibraryManager.BuildState)ar.AsyncState;
            bool success    = buildState.BuildFunc.EndInvoke(ar);

            if (success)
            {
                lock (this)
                {
                    RemoveLibraryBuildNotification();

                    var frm = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                    frm.Activated            += notification_Activated;
                    frm.Shown                += notification_Shown;
                    frm.ExploreLibrary       += notification_ExploreLibrary;
                    frm.NotificationComplete += notification_NotificationComplete;
                    Point anchor = NotificationAnchor;
                    frm.Left = anchor.X;
                    frm.Top  = anchor.Y - frm.Height;
                    if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                    {
                        NotificationContainerForm.BeginInvoke(new Action(() => MessageDlg.Show(NotificationContainerForm, buildState.ExtraMessage)));
                    }

                    Thread th = new Thread(frm.Notify)
                    {
                        Name = "BuildLibraryNotification", IsBackground = true
                    };                                                                                             // Not L10N
                    th.SetApartmentState(ApartmentState.STA);
                    th.Start();

                    Notification = frm;
                }
            }
        }
コード例 #2
0
 private void InvokeAction(Action action)
 {
     // Make sure the notification container form has not already been
     // destroyed on its own thread, before trying to post a message to the
     // thread.
     try
     {
         NotificationContainerForm.Invoke(action);
     }
     catch (ObjectDisposedException)
     {
         // The main window may close during an attempt to activate it,
         // and cause this exception.  Hard to figure out anything to do
         // but catch and ignore it.  Would be lots nicer, if it were
         // possible to show a .NET form without it activating itself.
         // Again, using NativeWindow is too much for this feature right now.
         // It does not help to test IsDisposed before calling Invoke.
     }
 }
コード例 #3
0
        public void LibraryBuildCompleteCallback(LibraryManager.BuildState buildState, bool success)
        {
            // Completion needs to happen on a separate thread because of the access to UI elements
            // In order to make sure the thread handle is released, it needs to call Application.ThreadExit()
            var threadComplete = BackgroundEventThreads.CreateThreadForAction(() =>
            {
                if (success && NotificationContainerForm.IsHandleCreated)
                {
                    // Only one form showing at a time
                    lock (this)
                    {
                        RemoveLibraryBuildNotification();

                        var frm                   = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                        frm.Activated            += notification_Activated;
                        frm.Shown                += notification_Shown;
                        frm.ExploreLibrary       += notification_ExploreLibrary;
                        frm.NotificationComplete += notification_NotificationComplete;
                        Point anchor              = NotificationAnchor;
                        frm.Left                  = anchor.X;
                        frm.Top                   = anchor.Y - frm.Height;
                        NotificationContainerForm.BeginInvoke(new Action(() =>
                        {
                            if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                            {
                                MessageDlg.Show(TopMostApplicationForm, buildState.ExtraMessage);
                            }
                            if (buildState.IrtStandard != null && !buildState.IrtStandard.Name.Equals(IrtStandard.EMPTY.Name) && AddIrts(buildState))
                            {
                                AddRetentionTimePredictor(buildState);
                            }
                        }));
                        frm.Start();
                        Assume.IsNull(Interlocked.Exchange(ref _notification, frm));
                    }
                }
            });

            threadComplete.Name = @"Library Build Completion";
            threadComplete.Start();
        }
コード例 #4
0
        public void LibraryBuildCompleteCallback(IAsyncResult ar)
        {
            var  buildState = (LibraryManager.BuildState)ar.AsyncState;
            bool success    = buildState.BuildFunc.EndInvoke(ar);

            if (success)
            {
                lock (this)
                {
                    RemoveLibraryBuildNotification();

                    var frm = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                    frm.Activated            += notification_Activated;
                    frm.Shown                += notification_Shown;
                    frm.ExploreLibrary       += notification_ExploreLibrary;
                    frm.NotificationComplete += notification_NotificationComplete;
                    Point anchor = NotificationAnchor;
                    frm.Left = anchor.X;
                    frm.Top  = anchor.Y - frm.Height;
                    NotificationContainerForm.BeginInvoke(new Action(() =>
                    {
                        if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                        {
                            MessageDlg.Show(TopMostApplicationForm, buildState.ExtraMessage);
                        }
                        if (buildState.IrtStandard != null && buildState.IrtStandard != IrtStandard.NULL && AddIrts(buildState))
                        {
                            AddRetentionTimePredictor(buildState);
                        }
                    }));
                    var thread = BackgroundEventThreads.CreateThreadForAction(frm.Notify);
                    thread.Name         = "BuildLibraryNotification"; // Not L10N
                    thread.IsBackground = true;
                    thread.Start();
                    Notification = frm;
                }
            }
        }
コード例 #5
0
        public void LibraryBuildCompleteCallback(LibraryManager.BuildState buildState, bool success)
        {
            // Completion needs to happen on a separate thread because of the access to UI elements
            // In order to make sure the thread handle is released, it needs to call Application.ThreadExit()
            var threadComplete = BackgroundEventThreads.CreateThreadForAction(() =>
            {
                if (success && NotificationContainerForm.IsHandleCreated)
                {
                    // Only one form showing at a time
                    lock (this)
                    {
                        RemoveLibraryBuildNotification();

                        var frm                   = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                        frm.Activated            += notification_Activated;
                        frm.Shown                += notification_Shown;
                        frm.ExploreLibrary       += notification_ExploreLibrary;
                        frm.NotificationComplete += notification_NotificationComplete;
                        Point anchor              = NotificationAnchor;
                        frm.Left                  = anchor.X;
                        frm.Top                   = anchor.Y - frm.Height;
                        NotificationContainerForm.BeginInvoke(new Action(() =>
                        {
                            if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                            {
                                MessageDlg.Show(TopMostApplicationForm, buildState.ExtraMessage);
                            }
                            if (buildState.IrtStandard != null && !buildState.IrtStandard.Name.Equals(IrtStandard.EMPTY.Name))
                            {
                                // Load library
                                Library lib = null;
                                using (var longWait = new LongWaitDlg {
                                    Text = Resources.LibraryBuildNotificationHandler_AddIrts_Loading_library
                                })
                                {
                                    var status = longWait.PerformWork(TopMostApplicationForm, 800, monitor =>
                                    {
                                        lib = NotificationContainer.LibraryManager.TryGetLibrary(buildState.LibrarySpec) ??
                                              NotificationContainer.LibraryManager.LoadLibrary(buildState.LibrarySpec, () => new DefaultFileLoadMonitor(monitor));
                                        foreach (var stream in lib.ReadStreams)
                                        {
                                            stream.CloseStream();
                                        }
                                    });
                                    if (status.IsCanceled)
                                    {
                                        lib = null;
                                    }
                                    if (status.IsError)
                                    {
                                        throw status.ErrorException;
                                    }
                                }
                                // Add iRTs to library
                                if (AddIrts(lib, buildState.LibrarySpec, buildState.IrtStandard, NotificationContainerForm, true))
                                {
                                    AddRetentionTimePredictor(buildState);
                                }
                            }
                        }));
                        frm.Start();
                        Assume.IsNull(Interlocked.Exchange(ref _notification, frm));
                    }
                }
            });

            threadComplete.Name = @"Library Build Completion";
            threadComplete.Start();
        }