Jump to content

Coding: How to notify PDN to redraw from effects workthread?


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.
 }
}

KaHuc.png
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...