Leo Violette
2009-04-03 21:57:06 UTC
I have a C# Windows Service.
My Service class contains a ProcessJob object that I've implemented.
In OnStart of my Service Class, I construct the ProcessJob instance and tell
it to look for and start a job if it finds one.
In OnStop, I tell my ProcessJob instance to stop whatever it is doing.
I've now added .NET Remoting capability to the windows Service. I have a
new class in my Service project to implement my .NET Remoting methods.
I added a StopCurrentJob .NET remoting method. I'm wondering how to access
the ProcessJob from my .NET Remoting service.
I need a method that get's me the main application class and then cast it to
my service so that I can get to the ProcessJob instance it has created.
Any help?
Main Service class.
JobService.cs
namespace nsJobService
{
public partial class class JobService : ServiceBase
{
protected override void OnStart(string[] args)
{
m_jobProcess = new JobProcessor();
m_jobProcess.BeginJob();
// Code here was added to configure .NET Remoting.
}
protected override void OnStop()
{
m_jobProcess.StopJob();
}
private JobProcessor m_jobProcess;
public JobProcessor JobProcess
{
get { return m_jobProcess; }
}
}
}
Utility class for processing jobs.
JobProcessor.cs implements JobProcessor
.NET Remoting Implementation class
using namespace nsJobService
internal class ImplementJobProcess : MarshalByRefObject,
ISharedJobProcessInterface
{
void ISharedJobProcessInterface.CancelRunningJob()
{
// How to code this?
JobService jobService = (JobService)Application.GetServiceBase();
//??????
jobService.JobProcessor.StopJob();
}
}
My Service class contains a ProcessJob object that I've implemented.
In OnStart of my Service Class, I construct the ProcessJob instance and tell
it to look for and start a job if it finds one.
In OnStop, I tell my ProcessJob instance to stop whatever it is doing.
I've now added .NET Remoting capability to the windows Service. I have a
new class in my Service project to implement my .NET Remoting methods.
I added a StopCurrentJob .NET remoting method. I'm wondering how to access
the ProcessJob from my .NET Remoting service.
I need a method that get's me the main application class and then cast it to
my service so that I can get to the ProcessJob instance it has created.
Any help?
Main Service class.
JobService.cs
namespace nsJobService
{
public partial class class JobService : ServiceBase
{
protected override void OnStart(string[] args)
{
m_jobProcess = new JobProcessor();
m_jobProcess.BeginJob();
// Code here was added to configure .NET Remoting.
}
protected override void OnStop()
{
m_jobProcess.StopJob();
}
private JobProcessor m_jobProcess;
public JobProcessor JobProcess
{
get { return m_jobProcess; }
}
}
}
Utility class for processing jobs.
JobProcessor.cs implements JobProcessor
.NET Remoting Implementation class
using namespace nsJobService
internal class ImplementJobProcess : MarshalByRefObject,
ISharedJobProcessInterface
{
void ISharedJobProcessInterface.CancelRunningJob()
{
// How to code this?
JobService jobService = (JobService)Application.GetServiceBase();
//??????
jobService.JobProcessor.StopJob();
}
}