Killing a long running Loop C# IIS - c#

I have a long running loop that kicks off in my web app on IIS running my C# code. I'm in development mode, so I'm attaching to the W3P3 process often, testing my loop, troubleshooting, etc.. and when I kill my interactive session in Visual Studio the loop keeps running. This is expected. What is not expected, is that after I kill the current running W3P3 process, the loop continues to perform. I have tested this many times and I just can't quite figure out how to kill the loop (kill the process, which process?).
I have no intent of coding, "is client still connected", because it is the correct behavior to continue to run, whether or not the client is connected or not, however in development mode I need to be able to kill it.
Which process is persisting and running the loop?

Related

Process.Start Hanging, Not Starting Process

I have an api running in IIS written in .net framework 4.7.1 that needs to start a console app, but when I call Process.Start(#"\\boxName\d$\moreFoldersHere\FileName.exe"), it hangs on execution, and the console app does not start. I have verified that the app pool under which the site is running has full perms to both the directory containing the exe and the exe itself, and I have made the service account an administrator on the box with no luck. I have no trouble running the app, but even when I set the app pool to run as myself, the behavior does not change.
Purely for context... the api needs to trigger a process that may take an unreasonable amount of time to complete. Obviously I don't want the api response waiting on it, so I don't want to wait for the result of the process; I just want to fire-and-forget. I also don't want iis cleanup killing it after some period of "no activity", and I need to potentially have multiple instances of this same process executing at the same time on the same box.
I found the answer... In IIS, in the App pool, LoadUserProfile needs to be set to True.
I'm not sure why it defaulted to False, but everything is working fine now.
Since it's a console app, your issue is likely the need to read the output. See this answer.

How to finish code execution after stopping windows service?

I'm using a simple windows service app. Some of the code takes around a minute to finish executing. If I want to rollout news changes to production, how do I ensure that even after I stopped the service, the service finished what ever it's executing?
Your new service would need to check to make sure the old process isn't running.
How can I verify if a Windows Service is running
A better way would be to fix your service so it can be shutdown in a reasonable length of time. A minute is much too long to stop a service.
Whatever it's doing needs to be able to cleanly stop or roll back on request.

WCF Service hard crashing Windows 2016

I have a web service running in IIS-10 on a Windows Server 2016 instance within a VM Hypervisor. A separate scheduled task calls functions of that web service during off peak times in order to retrieve status updates from a third party system. The scheduled task breaks the items that need to have statuses pulled into small batches and calls a function that retrieves / updates the records in parallel via Tasks and gives a return once all Tasks have completed.
Sometimes (every third time?), during this scheduled task, the app pool that the service is running on hangs. Log4Net stops logging, requests to the service do not get a response, IIS logging for the service is not updated with requests. There are no errors recorded in either my logs or in the windows event logs. When this happens, the app pool will stay in this state indefinitely. If I recycle the App Pool that the service is running on, the service will respond normally for ~30 seconds, and then the server will do a hard restart.
After the restart the event logs show the below error:
The computer has rebooted from a bugcheck. The bugcheck was: 0x00000139 (0x0000000000000003, 0xffffd60019506680, 0xffffd600195065d8, 0x0000000000000000).
The dmp file that is generated shows the same error code and identifies the file as ntoskrnl.exe.
All drivers are fully up to date. I have made sure all tasks and requests have timeouts. I have increased server resources past the point where that could be the cause. I have adjusted the batch size of items being processed.
I am out of troubleshooting ideas and would appreciate any help I can get.
I figured I would close this out in case anyone else has this very specific issue.
Digging through the dump, BHDRVX64.SYS (Symantec Antivirus) was on the stack immediately before the crash.
A 4 days later Symantec pushed an update https://support.symantec.com/en_US/article.INFO4367.html with a fix for the issue.
** If you hit a similar issue to this, start by uninstalling antivirus and seeing if the issue persists. After that, work through the list of kernel level processes returned by the 'fltmc' command in admin command prompt.

Application never finishes starting in debug, possibly Redis?

I have an asp.net web application that is hosted in Azure and using a Redis cache to manage session storage. Every so often, the application will hang when debugging in localhost for no apparent reason.
Essentially, in Visual Studio, I'll hit the start button. A new web browser window will open like it's about to open the page, but instead it will simply load and load forever. If I try pausing the debug session, it seems to always land somewhere within the Redis dll, but I can't be sure where exactly.
No matter how many times I kill all processes and restart Visual Studio, this behavior will continue until I restart my computer. What could possibly be causing this?
Redis was never designed to run on Windows, the version they make available is really only for testing purposes.
If you have issues with it hanging, it could be that it is miss-configured. This question on serverfault may help.

Console Application running in Task Scheduler without stop

I've created a C# console application that does some updates in a SQL server database. I've set that application in the Task Scheduler to run daily. The application is running fine, but I noticed that the task never stops but keeps showing "Running", I have to click "End" by myself to stop it.
How can I let the task stop by itself without forcing it to stop ?
The task would stop by it self under normal conditions.
What purpose does your application server? It's doing something to keep it alive, since a normal console application would just run its course and shut down.
You always have the options of just straight up murdering it at the end of it's job, but it would be a better choice to identify what is keeping it alive.
System.Environment.Exit(0);
Is it multithreaded? Do you have some backgroundworkers running or anything?
This has been solved by using the files created in Debug instead of Release in the scheduled task, but i'm not sure why is that.

Categories

Resources