Forum

Dynamic plugin blocking vvvv until finished. how to avoid

devvvv

#1

hi, there. i am still experimenting with dynamic plugins and tinkering with examples from the web.
I am having a plugin that is uploading a file to a server via HttpWebRequest.
Now during the upload v4 is freezing until the upload is done.
Is there any magic setting to let the plugin do the work in the background or do i have to write the right code with threading or any other scary stuff?


#2

threading could help, i’m no expert though


#3

yes, async calls or threading is the way to go…


#4

really? was hoping for a convenience kind of command like
thisWholePlugin = runInSeperateThreadAndDontBlockThePatch :) somehow…

So when i do not care about threading and the complicated async calls, everything calculated in a plugin that takes longer than a v4 mainloop frame will freeze the patch for that time. If the command proposed above is technically possible, is there any chance to have such an option for plugins in the future? There may be more scenarios to use it than fileupload but i also understand that in most cases you want a plugin to run in sync with v4. sorry if that are stupid questions… will have a look on the threading anyway.


#5

How about something like:

private class MyUploadData
{
  //everything needed to upload a file
}

public function MyUploadFunction(MyUploadData uploadData) {
  HttpWebRequest ...

}

public void Evaluate(int spreadMax) {
  MyUploadData d = new MyUploadData();
  //fill d with everything it needs
  ThreadPool.QueueUserWorkItem(MyUploadFunction, d);
}

#6

Thank you ft. I will try to get that example working for sure.
In the meanwhile I got it working with a little help from elsewhere.
Now using Webclient.UploadFileAsync and it works like a charm.
Really falling in love with the dynamic plugins and c#.
Still muuuuch to learn though…