MosaicManiac Posted June 2, 2009 Posted June 2, 2009 I'm working on a "collage paint" plug-in. http://paintdotnet.forumer.com/viewtopic.php?f=16&t=30254. The plugin requires some intensive processing and sometimes can take minutes. I don't want to block the UI thread but instead do the work in the background. So, I spin of my own work threads to do additional UI and processing. I haven't figured out how to notify the parent to redraw the client once my thread is done processing. This is quite evident when you use "Hue Adjustment" slider. Can someone point me in the right direction? Thanks, Peter Quote
Simon Brown Posted June 2, 2009 Posted June 2, 2009 I'm not sure HSL uses separate threading and I doubt using custom threading is the right way to do it, but i'd create a static event handler and subscribe to that from the parent. Quote
MosaicManiac Posted June 2, 2009 Author Posted June 2, 2009 Blocking a UI thread for long times is not an acceptable solution. In fact this was my first implementation and it was not usable. Custom threading seems to be the only way. I've looked at pretty much all event notifications and I'm using some. Which one did I miss? Do you have a code sample? Thanks Quote
Simon Brown Posted June 2, 2009 Posted June 2, 2009 Note that this won't work with IndirectUI. class SomeRandomEffectDialog : EffectConfigDialog { public SomeRandomEffect() { WorkerFinished += new EventHandler(WorkerFinished_EventHandler); } public static event EventHandler WorkerFinished; private static void OnWorkerFinished() { if(WorkerFinished != null) WorkerFinished(null, new EventArgs()); } private void WorkerMethod() { // Render your effect to a surface stored in the config token. OnWorkerFinished(); } private void OnControlChanged() { Thread t = new Thread(new ThreadStartInfo(WorkerMethod)); t.Start(); } private void WorkerFinished_EventHandler(object sender, EventArgs e) { // Ect. } } Quote
MosaicManiac Posted June 2, 2009 Author Posted June 2, 2009 Thank you Simon. This looks a lot like what I'm doing already. It still doesn't solve the issue how to notify parent to redraw itself. Quote
Simon Brown Posted June 2, 2009 Posted June 2, 2009 I'm not sure what you mean by "redraw," Paint.NET only renders the effect when the dialog is closed with a result of "OK" and when you tell it to. Quote
MosaicManiac Posted June 3, 2009 Author Posted June 3, 2009 I'm probably doing something a plugin is not intended to do. Probably the best way I can explain is on an example. Run the plugin http://paintdotnet.forumer.com/viewtopic.php?f=16&t=30254 Once the initial scene has render, move the "Hue Adjustment" slider. At that moment I start rendering new scene, spawn a new work thread and present a progress dialog. I could hold on to UI thread but the "Hue Adjustment" sliders becomes abnoxiously useless. When the work thread is finished and progress dialog goes away, I'd like to notify PDN to redraw. Currently to see the new rendered scene you have to interact with the dialog, for example move the Transparency slider. I hope this explains it. Thanks Simon for trying to help. Quote
Simon Brown Posted June 3, 2009 Posted June 3, 2009 Run the plugin http://paintdotnet.forumer.com/viewtopic.php?f=16&t=30254 I'm sorry, i'm using 3.5. Quote
Simon Brown Posted June 3, 2009 Posted June 3, 2009 Run the plugin http://paintdotnet.forumer.com/viewtopic.php?f=16&t=30254 I'm sorry, i'm using 3.5. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.