Click to See Complete Forum and Search --> : Multithreading


Suzi167
February 4th, 2009, 02:26 PM
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:


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

yraen
February 4th, 2009, 02:49 PM
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...

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

RaleTheBlade
February 4th, 2009, 02:51 PM
What does the ControllerJob method body look like?

Suzi167
February 4th, 2009, 02:57 PM
The _controller.StartProcessing basically calls another object called Watcher.StartProcessing,etc. which monitors a folder for dropped files in it.

Suzi167
February 4th, 2009, 03:41 PM
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