Running a workflow within another workflow - Both terminates - c#

I have been using windows workflow foundation and calling a workflow from another workflow.
Using .Net framework 4.6.1 along with MS SQL Server 2014. The whole scenario is working absolutely fine.
However, when I deploy it to a customer environment it starts terminating without an exception or log trace. I have added detail logging (printing log statements on different lines) but it terminates on different statements.
As debugging in customer environment is not a good idea, any pointers in identification of this issue would be appreciated.

Related

How to debug a C# service that stops for no reason on production server

We have implemented a pair of services in C# that send and receive faxes. These services have been running flawlessly for several years on several servers - until last week.
One of our clients upgraded to Windows Server 2012. We installed the services and all hellbroke loose.
Basically, one of the services appears to work for several minutes, and then, for some unknown reason - goes to the OnStop method. So someone, or something - is stopping it, but I don't know what it is.
How could I go about debugging this? I am new to C# and this is not my code.
Any help would be appreciated.
Is interesting the fact you are sending and receiving faxes: It colud be related to some Session 0 Insolation introduced with windows server 2008/2012, that could cause problem in graphic related services.
If you have some chanches to run the server on a developement machine, using a Windows7/8 box and a SYSTEM user, you can probably reproduce the problem.
If it only stops on the production server, it is reasonable that there is something different about the production server than your development server/workstation.
It is probably unlikely that you're allowed to hook a debugger into something on the production server, but the best way to handle this is just to log the he** out of the code.
You should introduce enough logging to figure out:
Where it stops
Why it stops (my money is on an exception)
The state of the application at that time (related to the crash)
This will probably have to be done in iterations, unless you go all out to begin with.
Services and logging go hand in hand, so just implement it.

StackOverflowException on Windows Server 2003 Enterprise Edition Service Pack 2

I have built a standalone console app that is throwing intermittent StackOverFlow exceptions only when installed on a Windows Server 2003 Enterprise Edition Service Pack 2 test machine. The code is far too complex to post, but here are the details:
Source code is C# VS 2010.
There are no recursive calls in the source code, but it does use a worker thread.
The running process is not terminated when the StackOverflowException occurs.
When the exception occurs, it will consistently occur in the same location.
When the exception occurs, it almost always occurs when the code is trying to initialize across a COM boundary i.e: CAsset asset = new CAsset() where CAsset is a COM object written in C++.
Replacing the direct initialization with a call to System.Activator.CreateInstance
System.Type assetType = System.Type.GetTypeFromProgID("GDMTCommon.HansenAsset");
object activated = System.Activator.CreateInstance(assetType);
asset = activated as CHansenAsset;
does not solve the problem, but it does move the point of failure to a different location in the code. Also the above code does not throw an error, but the asset variable is null after the direct cast. This instance is the one time that the failure does not occur on initializing a COM object.
The most baffling behavior is that I can run the tool on two different sets of source data on the test machine, and for one set of source data the code will run to completion without error, on the other the code fails.
I have installed the same tool on two different Windows 7 test machines and could not reproduce the error on either machine. I also installed the tool on a Windows Server 2003 Standard Edition Service Pack 2 test machine and could not reproduce the error on that machine.
Numerous searches have turned up a couple of other questions where code working on one OS starts throwing StackOverflowExceptions on when installed on Windows Server 2003 , but I did not see any definitive solutions.
I found this knowledge base article that seems to describe my problem:
http://support.microsoft.com/kb/915750
But according to the article, the problem is fixed in Service Pack 2 and I have verified that Service Pack 2 is installed on the test machine.
Any assistance will be greatly appreciated.
Regards,
Jay
Running Windows Update and applying all of the available updates to the machine resolved the stack overflow problems. Still unsure what was causing them in the first place. Since this was a client machine that I did not have access to, I had to wait for them to apply the updates.

CPU usage goes high in Asp.Net MVC application while longer process run by other utility

I have one application which is developed in ASP .NET MVC 3 which using a SQL server database.
Apart from this, I have one console application which calls an external web service and update the same database with the information and business rules. (Basically we iterate the records from Web service and process the business rule and update the same database), we have configured the console application with Windows scheduler to process it periodically.
The problem is, when my Console application runs periodically, it uses the 100% CPU usage (because we're getting more than 2000 records from web service), and because of that my current MVC application is gets haging OR sometime works very very slow because both application are configured on same windows server.
Could anybody please do let me know that How would I resolve this problem where I want both the things on same server because I have central database used by both application.
Thanks in advance.
You haven't given any detail that anyone can really provide resolution, so I'll simply suggest how I would approach it.
First, I would review the database schema with a DBA to make sure there aren't things like table locks (or if there are, come up with strategies to compensate for them). I would then use the SQL Server profiler to see where (or if) there are any bottle necks in SQL server while these things are running. I would then profile the console application to make sure it's not doing something it doesn't need to be doing. I might even consider profiling the web site to see if there's anything in there that might be contributing to slowness.
After that, I would figure out how to get rid of the Console application and work its functionality into the site. Spawning another application on a given web request is not scalable. More than a couple of those come in at once and you've got the potential to bog the server down very easily.

Windows program that always runs

I have a requirement that a Windows Forms C# .NET 2.0 program running in user-space (not a service) must always be running. As I'm not infallible and make coding mistakes, I wanted to know of any extra safeguards I could use to ensure this requirement is met. The things I've been thinking of are TaskScheduler to check it every 5 minutes, A stub watcher or a secondary process. Are these good / bad ideas?
Thanks,
Richard
EDIT: The reason I didn't use a service (the obvious and sensible answer!) was the program runs in a kiosk type environment and has has a heavy GUI component. The service option didn't work well across Windows 2000 - W7.
EDIT: The second reason not to use a service was the app needs internet access and on some of our customer sites, proxies are set up to only allow specific users (not the local system account) so it would be tricky to ensure access if multiple users log onto the machine.
Task scheduler is a cheap solution for this which does work. I use this to keep our Perforce Proxy server running (had some issues with the service), and so far there's been no problems - though now I've said that the server's probably exploded!
However, the most complete solution is a Windows service which invokes your app. You can make that service catch error return codes from the app, restart it on failure and notify you by email, which may help you diagnose and fix those issues. I think the Task Scheduler does something similar but it won't be able to provide as much insight into your application as a custom service.
If you're unsure of how to do that, then something like this should work:
http://www.codeproject.com/KB/install/csharpsvclesson1.aspx
There are three approaches that you can take:
Heartbeat Message.
A heartbeat is useful in a distributed application and is simply message that is sent (from let say a client to server) to confirm that it is still healthy/running.
Manager Process
A stub program, implemented as either a user process or a service. It launches the main application, monitors any unhandled exceptions, reports errors, and restarts on failure.
An exception guard on the entry point.
A try-catch-all in the application entry point.
I would recommend either of the first two options; the third option, the try-catch-all, is a particular nasty hack for the lazy and inexperienced programmer (IMHO).
I have successfully used both heartbeat and manager process in a large distributed application.
UPDATE
As for ready-to-go™ restart managers, take a look at the Windows API Codepack as discussed in Emmanuel Istace blog post (http://istacee.wordpress.com/2013/09/21/automatic-recovery-restart-in-net-application/).
You can install the package from https://www.nuget.org/packages/WindowsAPICodePack-Core/

Performance testing of Windows Forms application

We have a very old windows forms application that communicates with the server using .net remoting.
Can anyone recommend a method or a tool to performance test this.
Last time I looked there were no good tools for performance testing a windows application with many users.
You can use a profiler to see what is going on if the single user case is too slow.
If you only are about a hand full of users, most UI test tools could be used to record a script that you played back on a few machines.
Otherwise you need to write a command line application that talks to the server in the same way as the windows forms app, and then run many copies of that command line app.
Or get the server to log all calls in such a way as the calls can be played back.
In the past I have thought about getting each client to log the calls to the sever in the form of C# statements that could then be compiled to create a performance test program.
There are some systems that claims to record the communication between the client and the sever at the network level, and then play it back many times. This may work if it is sensible for lot of clients to send the some requests with the same params to the server, otherwise there will be lots of scripting within the tool to create custom requests for each client.
To do performance testing on the application, you can use a profiler, such as the ANTS Performance Profiler. I'm not sure if that's going to profile the network communication as well or not.
Alternatively, you can set up performance counters and record information that way when you run your app.

Categories

Resources