/// <summary> /// Applies the context changes over thread pool. /// </summary> private void ApplyContextChangesOverThreadPool(LinkChain <ContextChange> changeChain) { unchecked { ContextChange nextLink; ContextChange context = changeChain.Head; int contextCount = changeChain.Count; int contextIndex; for (contextIndex = 0; contextIndex <= (contextCount - 5); contextIndex += 5) { ContextChange context0 = context; nextLink = context0.NextLink; context0.NextLink = null; //+ paranoia ContextChange context1 = nextLink; nextLink = context1.NextLink; context1.NextLink = null; //+ paranoia ContextChange context2 = nextLink; nextLink = context2.NextLink; context2.NextLink = null; //+ paranoia ContextChange context3 = nextLink; nextLink = context3.NextLink; context3.NextLink = null; //+ paranoia ContextChange context4 = nextLink; nextLink = context4.NextLink; context4.NextLink = null; //+ paranoia context = nextLink; _threadPool.Add(new ContextChange[] { context0, context1, context2, context3, context4 }); } if (contextIndex != contextCount) { contextCount -= contextIndex; ContextChange[] contextArray = new ContextChange[contextCount]; contextIndex = 0; //for (; context != null; context = nextLink) for (; contextIndex < contextCount; context = nextLink) { nextLink = context.NextLink; context.NextLink = null; //+ paranoia contextArray[contextIndex++] = context; } _threadPool.Add(contextArray); } //+ clear changeChain.Clear(); } }
/// <summary> /// Applies the context changes inline. /// </summary> private void ApplyContextChangesInline(LinkChain <ContextChange> changeChain) { unchecked { ContextChange nextLink; for (ContextChange context = changeChain.Head; context != null; context = nextLink) { nextLink = context.NextLink; context.NextLink = null; //+ paranoia context.Execute(null); } //+ clear changeChain.Clear(); } }
/// <summary> /// Show image or thumbnail preview on drag enter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> internal static void Image_DragEnter(object sender, DragEventArgs e) { UIElement element = null; if (e.Data.GetData(DataFormats.FileDrop, true) is not string[] files) { var data = e.Data.GetData(DataFormats.Text); if (data != null) // Check if from web) { // Link element = new LinkChain(); } else { return; } }
/// <summary> /// Applies the pending adds and changes. /// </summary> private void ApplyPendingAddsAndChanges() { //+ pending adds foreach (var threadContext2 in _threadPool.ThreadContexts) { var threadContext = (ThreadContext)threadContext2; threadContext.Commands.Apply(); LinkChain <ContextChange> changeChain = threadContext.ChangeChain; //+ pending changes first allows threads to run int changeChainCount = changeChain.Count; if (changeChainCount > 10) { ApplyContextChangesOverThreadPool(changeChain); } else if (changeChainCount > 0) { ApplyContextChangesInline(changeChain); } } }
/// <summary> /// Show image or thumbnail preview on drag enter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> internal static void Image_DragEnter(object sender, DragEventArgs e) { if (!Properties.Settings.Default.FullscreenGallery && PicGallery.GalleryFunctions.IsOpen) { return; } UIElement element = null; if (e.Data.GetData(DataFormats.FileDrop, true) is not string[] files) { var data = e.Data.GetData(DataFormats.Text); if (data != null) // Check if from web) { // Link element = new LinkChain(); } else { return; } }