c# - How to make a Win Service run Long Term with Threading -
I have some workflows (a WorkflowApplication and WorkflowServiceHost) in a winning service that I need to keep the long running time Is hosting Since OnStart () requires that it is completed and returned to the OS, I have a main method that sets fire on the second thread in Threadpool. My onstart () looks primarily like this ServiceMainThread () is the method where my workflows are executed and the main functionality is implemented. When I start the service on my Windows 7 machine, it goes about 8 minutes later. At Win Server 2008, the thread never executes. So I think I've implemented incorrectly threading and what And for the full example purposes here, my on-site () implementation is: Is there anything clear that I can change my workflow to make it longer in the execution? While the loop looks a bit laughable (not to mention I do not like to delay the thread for any time) and I believe it can be a better solution than that. thread pool is fine to use instead of thread, but it seemed that the task is run workflow for 2minutes before removal start and stop now broken but I think I Onstop ( ) May be able to fix. When I do not block this thread is executing on workflows I do not have an empty block in ServiceMainThread (), while loop set did the same Update:. I get this exception from the net in the event log:
protected override zero onstart (string [] arg) {eventLog.WriteEntry ("start service ..."); ThreadPool.QueueUserWorkItem (New WaitCallback (ServiceMainThread)); Thread.Sleep (100); EventLogCms.WriteEntry ("service start."); }
ServiceMainThread
is kinda Seki I'm open to suggestions on what can be improved or any As the direction I am new to threading in .NET. Basic threading code ServiceMainThread coded such as:
private void ServiceMainThread (object state) {// .. .. workflow executed hanged eventLog.WriteEntry ( "workflow." ); While (living) {thread. Sleep (1); // ... ... Check workflow states and make sure they are still executing ...} // If action is required to be stopped and if necessary, display responsibilities. EventLog.WriteEntry ("workflow paused."); }
Secure Override Zero Ontop () {alive = false; This.haltEvent.WaitOne (); // haltEvent is of type ManualResetEvent}
p> server 2008 64-bit, that can Is there anything with my problem? Framework version: v4.0.30319 Description: The process was terminated due to an unused exception. Exception information: System.NullReferenceException ads: Ptm.ServiceMainThread (on System.Threading.ExecutionContext.Run on System.Threading.ExecutionContext.Run) (System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) (on System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) on System.Threading.ThreadHelper.ThreadStart ()
First of all, for a long-running thread, create your own thread
object and start it; Do not use Threadpool
. Thread pool is designed for small, relatively short-term tasks.
Second, there are several ways that you can keep your thread alive. The most basic that you have tried, which is finally a sleep (or other block) with a while
is loop. It is the most basic, though not necessarily the "best" there is that much more Constructive code execution and wake can allow for less iterations of check-sleep WaitHandle
is the other option, like designated names that can be accessed from other applications.
If however, you can not (or do not want to) modify other processes to inform your service of special events, then what do you have, basically, True, however, I encourage to choose the appropriate sleeping
time; Should you actually check every millisecond?
Comments
Post a Comment