Git Product home page Git Product logo

guiworker's Introduction

GUIWorker Cross Thread Call Example

This is an example of the complications of cross thread calling for C++ member functions. It is possible and quite easy but requires a large quantity of boilerplate code to invoke the function.

To call GUIWorkerForm::ExecuteTaskAWt with a single argument requires 10 lines of setup code and 2 lines of finalisation code. It also requires two methods in the class where ideally I would prefer one.

C# makes use of Delegates to resolve this issue, it is not ideal but better than the situation in this project.

According to the C++11 standard I should be able to call a member function in a new thread like this:

std::thread mythread = std::thread(&GUIWorkerForm::ExecuteTaskBWt, this, <arg>);

This should create a new thread, and call the &GUIWorkerForm::ExecuteTaskBWt method with this and the proivded argument that is fine but I want to use an existing thread (see workerthread.c).

Ideally, from the GUI thread I want to call a method like this where wt_ctx is the context of the worker thread created earlier:

CallMethodFromWorker(wt_ctx, &GUIWorkerForm::ExecuteTaskBWt, this, <arg>);

This requires the use of template functions and variadic arguments...

guiworker's People

Contributors

drcrane avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.