CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Multithreading

  1. #1
    Join Date
    Apr 2005
    Posts
    172

    Multithreading

    Hello All gurus,

    I have a multithreading question.

    I am writing a service which basically is going to be a listener which monitors a folder and when files are dropped in it...etc,etc..... in other words it will be running constantly until I stop the service.

    I have the following code:
    Code:
     protected override void OnStart(string[] args)
            {
                ThreadStart ControllerJob = new ThreadStart(_serviceController.StartProcessing);
                Thread thread = new Thread(ControllerJob);
                thread.Start();
            }

    The service registers fine and starts running but the folder monitoring is not quite working.
    I have a suspicion that it is because of the way I have the multithreading implemented because when I put
    a debug log message after the thread.Start() call I never get the message - and if that is really on a separate thread then I should - right?

    Can u by looking at my code tell me what is wrong with the way I have it?

    THanks very much in advance.

    SUsan

  2. #2
    Join Date
    Apr 2008
    Location
    Kentucky
    Posts
    73

    Re: Multithreading

    My limited experience doesn't see anything wrong with the code sample you supplied. Using the same general logic, I tossed a test together and it worked fine...

    Code:
            private void button1_Click(object sender, EventArgs e)
            {
                Thread _test = new Thread(new ThreadStart(MyThread));
                _test.Start();
                MessageBox.Show("Hi");
            }
    
            private void MyThread()
            {
                Thread.Sleep(5000);
                MessageBox.Show("Bye");
            }
    The "Hi" message appears before the "Bye" message

  3. #3
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Multithreading

    What does the ControllerJob method body look like?
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  4. #4
    Join Date
    Apr 2005
    Posts
    172

    Re: Multithreading

    The _controller.StartProcessing basically calls another object called Watcher.StartProcessing,etc. which monitors a folder for dropped files in it.

  5. #5
    Join Date
    Apr 2005
    Posts
    172

    Re: Multithreading

    Thanks to all of you who replied.
    I just wanted to say that I resolved the issue.

    After looking at the code I saw that the threads were running well indeed ( based on the post that yraen made I noticed a problem with my log) and it was a database issue.

    Thanks again for taking the time and looking at my problem

    Susan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured