This question already has answers here:
How to debug a single thread in Visual Studio?
(12 answers)
Closed 8 years ago.
I have a client/server multithreaded application and one thread is used to send a regular ping to the server. The problem appears when i want to debug other threads it also blocks my ping thread. I already tryed options in Visual Studio Debug->Windows->Thread but don't want to use it each time i need to debug a part of my application.
Moreover as I work in a team I can't force my teammates to use this technique. How can I do this without much effort for them (macro, ...)?
Thanks
edit: It's not a duplicate thread! I don't want to use conditional break point every time i need to debug my application! And don't want to complexity the debug procedure for the rest of my team. I searched everywhere and nobody spoke about executing the thread in another Process
Thanks everyone i finally found an answer to my question!
As #hyde suggested i run my Ping loop in another process, but rather than create another program i dynamically create and execute it from my code
as seen in this topic:
Is it possible to dynamically compile and execute C# code fragments?
And this more advanced topic:
http://simeonpilgrim.com/blog/2007/12/04/compiling-and-running-code-at-runtime/
But after all i still had a problem... I needed to share my NetworkStream between my Main Application and his Child (needed to send to the same server Thread), so i gave to the child the NetworkStream by reflection.
Now work correctly, thanks!
Related
This question already has answers here:
How many times program has run? C#
(9 answers)
Closed 5 years ago.
I would like to track number of times a particular exe is executed. WIth my research so far I didn't find much of a programatic way to get the data. I found some applications like windows prefetch which could help but in my organisation I'm not allowed to use these third party applications. Kindly help me out with a way to get the data with C# code/powershell or any simple way a windows admin know of. Appreciate it!
The only reliable way to track every single exe execution is to design an app to run in Kenrel mode..
The other not that reliable way is to periodically poll for running processes in the system, using Process.GetProcessByName method for instance.
I've been looking for a way to do some stuff before an application starts and stop the started application and execute after "the stuff" is completed.
Like an Antivirus applications, when you open an application which may be dangerous or has no certification, it executes a scanning and only after that execution allow the application to starts.
Already tried with watchers and WMI (C#) but no success, since the calling event happens before the application starts and there is no way to cancel the opening.
If there is a name for that technique or someone knows an example code in C++ or C# or even any other language.
For those who are downvoting the question at least have the F** balls to explain why is downvoting...
It's a legitimate question! Maybe i miss explain it but still a legitimate question. Ohh I forgot, in many years of your career you already had to know everything... What would happen if you lost internet connection for three days? Are you still be productive? Maybe you guys had the API and documentation injected by Tank from Matrix... That's how NEO learn to fight.
Thanks
One option (which might be used by antiviruses, but not sure) is described here:
https://www.codeproject.com/Articles/11985/Hooking-the-native-API-and-controlling-process-cre
Basically, hooking the functions NtCreateFile(), NtOpenFile() or NtCreateSection() (the last one being mentioned as the preferred).
However, the hook must be done from inside a kernel mode driver, which might be a "slight inconvenience" (especially under 64-bit Windows, where the drivers must be signed AFAIK).
Some options also mentioned here: How does a Windows antivirus hook into the file access process?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have two windows C# WinForms applications that behave the same way related to this issue. The behavior exhibits if the applications are ran in this order:
Main application starts up and part of its normal working process opens some sockets; mixture of tcp udp and multicast.
At some time pressing a button it starts another application using C# process related libraries. The second app starts ok and all is ok.
It is known and acceptable that if I start a second instance of my main app the second instance won't be able to use the sockets the first one owns.
The issue that I have is that if I shutdown the first app and restart, it won't be able to acquire the sockets anymore... until the child app is also shutdown.
Note that the second app doesn't use ANY sockets whatsoever, but somehow windows keeps the sockets locked until the second app shuts down.
I HAVE THIS QUESTION RELATED TO PROGRAMMING IN C# WIN FORMS WHICH IS ON THE TOPIC NOW WITH CAPITAL LETTERS FOR PEOPLE WHO CAN NOT DISTINGUISH ON/OFF TOPIC:
how do I solve this so that I don't need to shutdown the second app for the first one to be able to acquire its sockets (WHICH -i know - ARE FREE).
This is normal handle inheritance behavior. Unfortunately the .Net Process.Start is passing true as bInheritHandles to CreateProcess (NB. an open request to allow control of this behavior exists: Make Process.Start have a option to change handle inheritance). As a work around, use the native CreateProcess instead, see When System.Diagnostics.Process creates a process, it inherits inheritable handles from the parent process.
I have multiple startup projects in my client/server solution. The server is a Console app and the client is a WinForms app. The server/console is launched first in case that matters.
Now there is a deadlock caused by some synchronization client-side code that blocks the server. Thread synchronization is done using simple lock statements.
When the deadlock occurs, both apps freeze of course and hitting pause/break in VS only breaks the server app, not the client. There are two questions here:
How could I choose which project to break out of multiple start up projects?
If a lock statement is stuck in a deadlock, is there a way to find out which line of code has a current lock on that object?
I think your best solution would be to debug your client and server in separate instances of visual studio and setting startup projects accordingly.
As for the second question, I normally set a guid and output on create and release of a lock. to see if this is happening. If it is, I set breakpoints and debug and look at the stack to see where on the calls are coming from. You may be able to output System.Environment.StackTrace to a log to get this information, but I've ever attempted it.
You can use 2 Visual studios. One starting the console, one starting the server
I Would check if you really need a lock statement.
What do you want to lock ?
Do you always need a exclusive lock ?
Or are there some operations which can happen in parallel and only some which are exclusive ?
In this case you could use the ReaderWriterLockSlim
This can reduce the risk of deadlocks.
I'm a bit of a beginner as far as programming is concerned. And looking at stack overflow I haven't found anything that quite answers my question.
I have created a C# console application that is used to push an XML file to a web service that I don't control. It does this by creating an http webrequest. The service will probably be running on windows server 2008, or a win 7 varient. Development is done in VS 2010.
My end goal is to run this program twice a day with little user involement. And I was told that services were the best way to do this. I know that services do not take user input and that outputs are usually to a log file. My console app dosn't take user input but must have the ability to C.R.U.D. files. Beacuse it creates and then reads an XMl file into the web request. If needed I should have no problems having it write any errors to a log file, but at current though it creates/sends an error report via email.
I have 2 questions:
Question 1:
I would like this service to call the application every 12 hours, Is it more reliable/better practice to use a service to determine when to run the application? Or use windows' built in scheduler, or a .net solution like quark? I'm looking for reliability and also, little user involvement. Kind of a set and forget deal.
Question 2:
What would the suggested best practice be for converting my program?
INFO: I have previously created a empty windows service that I would like to fold my application into. (This was done via tutorial, the service contains all that is needed to for a service but it dosn't do anything... yet! OnStart, OnStop, installer etc.) What would be the best way to do it? Should I call my application inside the service's OnStart() method? Our should I add the application as a dll to the service. It's not that I don't think I could do it. It's just my searches on the matter seem to point out that it would be better to just start from a service and add some code to that. My goal would be to minimise the code needed to convert this application.
Thanks for all your help,
Chris
I like standalone programs run by the scheduler because they are easier to write and test.
Services would be more appropriate when they have to be running all the time...say to monitor something.
Question 1: Personally running twice a day seems like a scheduled task type of operation
Question 2: I'd describe it as: more or less put the body of static void Main(string[] args) into the OnStart method. Then also create a timer in OnStart which will call the trigger function in your class. But then I've only stumbled my way through writing windows services so I'm not 100% certain on this advice...
One consideration might be whats the risk of anything failing in the process? If there is a chance of an unhandled exception, the service will die and either would need special settings to restart it or complete error handling to be coded. Where a scheduled task will always automatically retry at the next trigger interval.