1

Ok, so i have Call1 in a webservice that will start a bacground worker thread to start doing some processing, but would like to have another call (Call2) that will monitor the original Worker Thread via a reference?

Any suggestions on how to do this? I'd really like to stay away from a WinService to do my processing. As i need it to be more realtime.

Jan de Jager
  • 870
  • 2
  • 13
  • 35
  • I'm not sure I understand what you mean by Call2 to "monitor" the thread. Do you mean for Call2 to look at some progress status related to the task the thread is doing and report back to the caller? – AnthonyWJones Aug 06 '09 at 08:46
  • Yip thats exacly what i need. I think i have found an answer here ... http://stackoverflow.com/questions/228775/net-web-service-backgroundworker-threads – Jan de Jager Aug 06 '09 at 08:48
  • This will work but does not hive a good mechanism to check that thread from Call2.. – Jan de Jager Aug 06 '09 at 08:49

1 Answers1

2

I don't see why using a Service application should be a problem. Services run all the time and monitoring them can be done it real time.

But, if you really don't want to go that way then there are other options. It is possible to start a new thread, using the ThreadPool or by starting a new Thread manually, and that thread will run in the background of the application pool where your web service runs.

You may want to use a task scheduler library for this. Check out Quartz.net for this.

Be aware that the app domain where your web service runs may be killed at any time if IIS decides it is necessary, so there is no guarantee that the job will complete. Using a Service application will fix this.

Rune Grimstad
  • 35,612
  • 10
  • 61
  • 76
  • I didn't think about the app domain issue. You're right, this is not going to be save at all... How easy is it to send a direct event to the windows service instead of relying on a timer to check the DB for a new job? – Jan de Jager Aug 06 '09 at 08:53
  • 1
    If you are on .NET 3.5 you can host a web service directly in your service application using WCF. That way you can expose methods that interact with your service directly. If that isn't an option then you can use Remoting to communicate with your service application from your web service. It's not very difficult, but more clumsy than the WCF approach. – Rune Grimstad Aug 06 '09 at 09:00