Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello friends,

I want to make an application that would work the same as Windows Task Scheduler.

I will create the entries into the database and I want an application that will take the events from the database every 1 minute and will execute using multithreading.

I am using .Net Framework 3.5

For this I have analysed a lot and got that ThreadPool can be used.
Can anybody suggest me for this in detail?

Your favour is highly appreciated.

Thanks in advance,

Saurabh Kumar
"REMOVED MAIL*
Posted
Updated 21-Dec-10 23:06pm
v2
Comments
JF2015 22-Dec-10 5:07am    
Edited to remove mail address. Never post your mail address in a public forum to avoid spam. You will be automatically notified if someone answers your question.

Well, depends how you want to implement this.
As far as i understand, your event will be raised by single thread.
All code written in event handler, will be running on single thread.
But, now you start the multi-threading.

For example, if you read some data from database, let's assume there are 100 entries to analyze, you can start 4 threads, for 25 rows.
for(int i =0;i<4;i++){
 int startRow = i * 25;
 ThreadPool.QueueUserWorkItem(new WaitCallback((Object n) => {
  int row = (Int32)row;
  //Do some job
}),startRow);

}


Also, you could use new parallel task library for .Net 4.
 
Share this answer
 
v2
Comments
ely_bob 22-Dec-10 15:46pm    
If your starting fresh you will want to target .Net 4.0 it will make your life easier.
saurabh_jsr 22-Dec-10 23:44pm    
Hi ely_bob,

Thanks for the reply. What I actually need that there will be the names of batch programs which will be fetched by our application. According to me, there should be one thread fetching the data(batch program names) from the database every 1 minute and we should put those batch programs in ThreadPool to execute. I am not getting this how to implement ?
Hello friends,

Finally I got the solution myself after analysing more. Thanks to :-D ely_bob :-D for entertaining.

Solution :-

I took one Queue<string> for storing the events every 1 minute using BackgroundWorker class and pass those events into the ThreadPool using ThreadPool.QueueUserWorkItem.

Pls advise if there is any problem in using ThreadPool.QueueUserWorkItem or any other better solution.

Which one is better to use QueueUserWorkItem or RegisterWaitForSingleObject ?


And how to use RegisterWaitForSingleObject. Please reply in details.

Saurabh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900