-
February 4th, 2009, 03:26 PM
#1
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
-
February 4th, 2009, 03:49 PM
#2
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
-
February 4th, 2009, 03:51 PM
#3
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
-
February 4th, 2009, 03:57 PM
#4
Re: Multithreading
The _controller.StartProcessing basically calls another object called Watcher.StartProcessing,etc. which monitors a folder for dropped files in it.
-
February 4th, 2009, 04:41 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|