none
Anyone got a clue on multithreading? RRS feed

  • Question

  • Hi, despite a month of c# - I am still quite bad at this language. I was wondering if anyone has 

    written code for a multi-threading program. I have written one that is comprised of an event driven kinect class along

    with a background worker on the mainwindow constantly updating the UI. I have noticed that there's a significant

    speed up. But the reason I build it in the first place was to do some heavy image processing- my problem

    lies in the fact that I couldn't update the images (feed it back to the background worker properly) that I have

    processed since it belonged to another thread.

     

    I know my problem sounds confusing. But all I need is maybe just a little structural guidance on how to build such

    an efficient program. Thanks in advance!

    Thursday, August 4, 2011 3:40 AM

Answers

All replies

  • I'm going to guess that this issue is the same you asked in http://social.msdn.microsoft.com/Forums/en-US/kinectsdknuiapi/thread/89f26712-c832-40d9-866b-6ad2eed1befe, which I responded to already.

    Let me know otherwise, and if you need more help please post some code and describe more details around your scenario.

    Eddy


    I'm here to help
    Friday, September 30, 2011 2:02 AM
  • Hey there,

    I wrote a Multithreaded Application with 4 different threads.

     

    The first (view) is the mainthread.

    The second is a controller thread (mvc pattern) that communicates with the view.

    The third and fourth are workerthreads. They get some information from controller, calculating some trivial stuff and sending back to the controller.

     

    It's not yet ready, I have to add some more comments and maybe implement a eventhandler in the view to be able to fire an event from controller to view...

     

    If you are interested, I could finish the "sample" and send it to you.

     

    Cheers,

    Simon

    Friday, September 30, 2011 8:36 AM
  • Hey there,

    I wrote a Multithreaded Application with 4 different threads.

     

    The first (view) is the mainthread.

    The second is a controller thread (mvc pattern) that communicates with the view.

    The third and fourth are workerthreads. They get some information from controller, calculating some trivial stuff and sending back to the controller.

     

    It's not yet ready, I have to add some more comments and maybe implement a eventhandler in the view to be able to fire an event from controller to view...

     

    If you are interested, I could finish the "sample" and send it to you.

     

    Cheers,

    Simon


    That would be extremely helpful! Thanks in advance!
    Friday, September 30, 2011 1:41 PM
  • http://www.file-upload.net/download-3781748/MultiThreaded_Sample.zip.html

     

    Hope you understand it! I added some comments.

     

    Please shoot me a mail if you dont understand or if you have some improvements!

     

    Thanks

     

     

    EDIT [* Got a solution]

    Hey Guys, I really need your Help.

    I dont know how to wake up a thread, when I shoot with an eventhandler.

    The example above uses waithandles but I dont know how to handle it with an eventhandler!

    Help is very appreciated!!

    Thanks.

    What I am planing to do is to run SpeechRecognition of Kinect in a single Thread!

    Thanks

     

    * I dont know how and why but seems to be fixed now.

    I thought, I could not interrupt a waiting thread with a simple eventhandler, but you can! Thats really awesome!

     

    If you want to try by yourselve you can take the sample above and change some line of codes:

    [1] maybe you recognized the eventhandler in controller, that was some previous work, that we can use now!

    [2] Copy the waitmethod in worker.cs and rename it to waitmethod2.

    It should look like:

    public void WaitMethod2()
    {
    	while(WaitHandle.WaitAny(events.EventArray) != 1)
    	{
    
    	}
    }



    In Constructor of Worker add:

    Controller.NewDataFromController += new Controller.NewDataFromControllerHandler(handle)



    Add a method into worker.cs called handle!

    public void handle(object o, sender s)
    {
    	Console.WriteLine("Hello Controller, you interrupted me!");
    }

    Now you can change the WaitMethod of controller. At case:ThreadID.View add
    OnNewDataFromController();

    And see what happens!



    Wednesday, October 5, 2011 11:20 AM
  • Sadly nobody replied and critizised something.

    Anyway, as I continued searching in the internet for c# threading I found a lot more easy code snippets and samples.

    For example you can use Parallel.For to iterate through elements parallel.

    Or you can compute methods asynchronously.

     

    So keep finding good solutions, folks ;-)

    Tuesday, October 11, 2011 8:38 AM