How does one start a process from CruiseControl .NET that persists after CC .NET exits? - cruisecontrol.net

I have a program that normally runs constantly. Whenever there is a new checkin to Subversion, CC .NET kills the program and makes a new build. I want to start a new instance of the program from CC .NET.
Right now, if I use <executable>, then CC .NET hangs while it waits for the process to end, which will never come by definition.

As far as I know there is no way to get CC.NET to launch something without it getting a return value and not have an exception. So to get around this my first thought would be to use the executable task to call some form of script, which can then launch the exe and return back to CruiseControl.

Related

Unable to debug in Visual Studio because process can not access file

When I try to debug in Visual Studio I get the error message:
Unable to copy file "C:\Users\Name\Dropbox\Company Name\Development\Product Name 4 - Release Candidate\packages\MahApps.Metro.1.1.2.0\lib\net45\MahApps.Metro.dll" to "bin\Debug\MahApps.Metro.dll". The process cannot access the file 'bin\Debug\MahApps.Metro.dll' because it is being used by another process. Product Name 4 - Release Candidate
How can I fix this error?
This happens all the time in Dropbox. Dropbox does some occasional (very brief) locking of files as it is indexing them, and if you happen to attempt to open a file handle with the write attribute set at the same moment, the program will receive a file I/O exception (this can happen to your own code as well, so if you regularly work in Dropbox, be sure to handle that gracefully).
Try compiling/running it again and see if the problem goes away. If not, then you likely still have an instance of your application running in the background. This can occur if your program ever forks. VS will terminate the original process, but often not forked processes from it. Check task manager to be sure. It will be listed as a background process in Windows 8/8.1

DetourCreateProcessWithDllEx replacement

I am trying to hook detours dll into my application it works but my application launches another exe. I can't attach to that exe because it says launch previous application and closes.
What I am trying to ask is, is there something in detours API that allows me to hook onto a process?

prevent vstest discovery engine locking DLLs

I have some C# unit tests for a VS2012 project which calls a VS2010 c++ DLL using DllImport pinvoke.
As a pre-build event for the test project, I copy the latest version of the DLL to the binary project for the test.
This repeatedly fails if vstest.discoveryengine is running. It appears that the 'discovery engine' is loading the tests and holding the lock on the DLL.
If I kill vstest discovery engine, then I can build and run the tests. otherwise the build fails, and VS2012 offers to run a previous version ( with a model dialog which doesn't have a 'don't show this message again' option)
Is there something I can do to either force the test project to unload the DLL when not actually running the tests, or to disable the background discovery executable?
I've hacked a workaround by creating an executable called Kealakekua which kills vstest.discoveryengine.x86, vstest.executionengine.x86, and with that as the first part of the pre-build event it can copy the files and build, but would prefer not to be fighting visual studio for my file.
I recently also had this issue and the problem was caused by my own user code.
During test discovery all the test classes are instantiated and in one of our test class constructors, a quite complex business classes was initialized. The problem is that during initialization of it a background thread was created, that did the following:
socket.Read(...)
This thread kept running forever waiting for some socket data to arrive and as a result locked our assembly.
So the solution for me was to make sure this code won't get called during test discovery.
You can check, if you are affected by this issue, by attaching Visual Studio to the test discovery engine when it has locked some assembly. After pressing pause you normally will see, that the current executing line is somewhere in your own user code (also check the Threads window).
I had a similar problem where I created a "Test" project that didn't actually have any tests in it. (As a C++ Library developer I wanted to make sure that certain headers were able to be compiled with CLR enabled, so I made a fake CLR project to just compile them with CLR. If it compiled, it passed.) The DLL created was being held open indefinitely by the vstest.discoveryengine.
I fixed it by adding an Ignored test to the project. I think vstest.discoveryengine will hold on to the dll until it finds all the tests in the dll, but if there are no tests to be found, then it will hold onto it forever.
The test I added (I think it is the default test) Note the TEST_IGNORE() to make sure it isn't executed:
#include <CppUnitTest.h>
namespace CLRTests
{
TEST_CLASS(CLRTestsClass)
{
public:
BEGIN_TEST_METHOD_ATTRIBUTE(CLRTest1)
TEST_OWNER(L"")
TEST_DESCRIPTION(L"")
TEST_PRIORITY(1)
TEST_IGNORE()
END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(CLRTest1)
{
// TODO: Your test code here
}
};
}
I hope this is possible in your situation.

How to have just ONE instance running of an exe with 3.5 .NET framework and CE windows 5.0

I've searched long and hard for an answer to my question and have found answers only to a class that does not exist in the 3.5 .NET frameworks version (and with CE Windows 5.0.) Also, it's Visual C# with Visual Studio 2008.
When I try the following (using System.Threading)
bool ok;
Mutex myMutex = new Mutex();
ok = Mutex(true,"scanner", out ok);
The compiler complains that the Mutex is a type, but used as a variable. If I use a [STAThread], it also complains that it can't find it and I"m forced to use [MTAThread].
Are the classes for the mobile device type of c# programs the same for console based ones? I'm somewhat new to this and the idea of how to declare, use, lock and everything you wanted to know about a mutex is making my head sore. O.o I suspect it's because the classes are different from the console verseions and the mobile versions.
It seems so simple, create a mutex, check for it's existance, if so then don't start a new exe instance. That is all I want...just run one instance of any exe. This is a mobile device thus it's a standalone and I never have to worry about anyone else using the .exe. Just need to stop the user from tapping the start button 15 times and having 15 instances of the application running (then complain about low memory usage!)
I've read that a good way is to create a thread, lock it then check if the lock was successful to test if an instance of an exe is already running, close it if so else run the exe. Is there an easier way to do this?
One way to approach this would be to open a file for writing. Only one instance of the application could obtain this lock at a time. On startup, try and obtain a file handle for writing, if it fails, there must be another instance already running: exit immediately.
I think you can forget mutexes since we are talking about separate proceses here.

Fork process with CC .NET

Is there any way to fork a process inside Cruise Control .NET? I want CC .NET to launch a program when everything's done but right now, CC .NET insists on waiting for the program to close before saying that the build is complete.
The program that is launched must run for up to weeks at a time.
The way I would do it is to use a PowerShell or Batch script. The script can launch your process and return back normally to CC.NET after spawning the executable. This is the only way I can see doing it, as CC.NET does need to know it returned and the script can return, even with the process you spawned still out there running. A sample PowerShell script that will do what you want. Then you just call the powershell script with the path to the exe as a paratemeter.
param( [string] $exePath = $(throw "A path to executable required.")
)
Invoke-Item $exePath
here on CC.NET 1.5 would be how to set up the powershell task
<powershell>
<script>yourScriptName.ps1</script>
<scriptsDirectory>D:\CruiseControl</scriptsDirectory>
<buildArgs>full path to exe you want to kick-off</buildArgs>
</powershell>
How about this... 2 Small programs
1) A process that runs all the time (maybe a windows service?), and listens on a tcp socket, when it gets a connection, execute your 3 week process.
2) A process that can be called by CC.NET, and opens a tcp connection to process #1, and then exits.
You could use any form of inter-process communication, but TCP sockets are easy and reliable.
Put the launch of the program into a separate CCNET project and add a ForceBuildPublisher to the original project.
<project name="OriginalProject">
<!-- ... -->
<publishers>
<!-- ... -->
<forcebuild>
<project>LaunchProgram</project>
</forcebuild>
</publishers>
</project>
I haven't tried the solution with powershell(the selected answer), but I use ruby rake and whatever I tried to fork independent process group with ruby library, CruiseControl STILL INSIST on waiting for the asynchronous process to finish.
For me; The only way to fork independent daemon process /server application successfully with CCNET is using task scheduler (https://stackoverflow.com/a/14679992/423356)
so use schtasks.exe to create a throwaway run once task to start your process
you can call schtasks and set the start time dynamically using batch file, ruby rake or powershell.

Resources