Hello
I’m using a long running crop method from a Canvas Object. I learned this out of Eugene Dakins Canvas Book Ex 8-2. Below. If it’s small crop #Pragma DisableBackgroundTasks work fine. In my project I am doing a large crop where I’m getting a not responding message and my crop window jumps behind my main window. This creates a poor user experience bug that have to fix.
Paul Levfebvere did a Xojo Youtube training video on threading back in 2018 that has the exact solution to my problem to fix my bug. This uses a Thread, Timer & Progress Bar. The rule the long running code must run in the thread event and must not touch any part of the user interface. I run my long running crop code from a button event on my crop picture window. In Pauls first threading example (which I can’t find in the old hubwiz docs).
He takes the code from the button event and put’s it in the Thread event. I thought oh that should be easy. I put my slow long running code in the Thread event. Well my canvas object method runs from a Canvas that is on the window interface. Throws an Error. That means I have the run the code below from the Canvas Object. I Jumped in and tried to figure it out from there - confussion??!! I’m working this from Eugenes code example to keep it simple. How do I tackle this were the thread event doesn’t choke on it?
`
Preformatted text`Crop(X as Integer, Y as Integer, Width as Integer, Height as Integer, Pic as Picture)
#Pragma DisableBackgroundTasks
//Crop the picture
//Create a new picture with width and height
Dim NewPic as Picture
NewPic = new Picture(Width,Height)
Dim w,h as Integer
//Copy pixels from old picture to new picture
For w = 0 to Width //Go through each row
For h = 0 to Height //Go through each column
NewPic.RGBSurface.Pixel(w,h) = Pic.RGBSurface.Pixel(w+X,h+Y) 'Copy Pixels
Next h
Next w
//Return the cropped picture
Return NewPic