Running C# like java [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Running java in batch would look like this
#ECHO OFF
java -Xmx512m -Xms512m -jar "PROGRAM.jar"
PAUSE
that would give it 512mb of ram. How could I do that in C#?

The compiled .exe file from c# has a header, which can be executed by the windows shell, with double click, as how you would start Java in command line, but the command line it would be saved into a bat file. It is very different from a native, win32 exe. It needs a Java like virtual machine, just the runtime compilation is different.
There are many options how to give launch and runtime parameters, one of is the config file. Please take a look Here.

Use Windows Job Objects API.
Jobs can limit memory usage and process priority.

There are 2 interpretations of your question as currently written:
1 - If you need to call a C# application from the command line / batch file just
Generate an EXE (such as a Console Application)
Call it directly by its filename (for example C:\MyApp\MyApp.exe)
2 - Limiting the amount of memory a certain program may consume is a bad idea.
Make sure your application only consumes the neccesary memory by writing good code.
I'm not aware of a mechanism that will limit the amount of memory a given .Net application can consume. And if it were such a thing, it's still a bad idea. Whenever the application reached that limit it would simply crash with an OutOfMemoryException.

Related

How to convert C# console app to Winforms or other GUI? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have written a long console app (over 1000 lines of code) and I want it to have a GUI. I was wondering if there was a way to quickly convert it to Winforms or other GUI?
I saw this article online that mentions how to convert console apps to Winforms, but it's not helping:
http://saezndaree.wordpress.com/2009/03/29/how-to-redirect-the-consoles-output-to-a-textbox-in-c/
When I followed the instructions on there, I was able to add a Winforms part to my program. But when I compile it, the Winforms does not include the Console app component of the program. My Form.cs includes the Winforms and Program.cs is the console app part with >1000 lines of code that I wrote before. Compiling it, only the part in the Form.cs runs. The Program.cs part doesn't run. For example, I have many "Console.Writeline" and "Console.Readline" parts in the Program.cs, but they run after I add the "Form.cs" to the program
You can not have two entry points in your program. Better to move your 1000 lines of code to a separate class so you have flexibility to either run from console or winforms (depending on which one is set as startup project)
I would suggest to convert the core functionality to a class library that can be called from both the command line or GUI application whichever is required.
As a quick measure (but weird too) on every event on the GUI application, you may call the command line application too. For this the command line application will receive inputs as parameter and will return output as text which can be shown on the GUI.
Please take this as a starting point as it may not fully apply in your case.

Best way to design distributed simulation [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm designing a program that uses a third party electrical solver.
I want to perform monte carlo simulations on large electrical grids and most of the times the program (mine) takes hours.
Because of this I thought that if I create a client in other computer I could call from my computer (and vice versa) I would have a nice distributed simulator.
Since I lack the knowlwdge, I would like to know what is the best way (if even possible) to "invoque" a program installed in another computer in the local network to do a specific task: simulate a file that I send and return the results back. The idea is to call the solver in lets say 10 computers at a time and gather the results asynchronically.
The language I use is C#.
I hope that my question is clear enough.
The easiest is to have a shared drive on the network, to which all computers have access. Then your app saves the input file (or one input file per machine, depends how you want to do it) on the shared drive, and your app starts another app remotely on each client. It monitors each one it starts for the exit status. After all of them have exited, it takes the output files and combines them and processes the data. Job done. The simplest "remote process" invocation is probably through psexec which you can download from technet, we have used it very successfully and very simple to use. The top two answers of How to execute process on remote machine, in C# have other good ideas: I think you will find them more overhead (longer to implement) but will give you more power in the long run.

Detect WinAPI calls [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm refactoring an application used by the employees of an insurance carrier, they have had some problems with some kind of malware on their computers that was controlling this application to do bad things, or at least that's what they say.
I'm pretty sure the malware is using the Win API to make calls to the application instance, so my question is, there's any way to detect if a real user is controlling the application or it's being controlled by another process through calls to the Win API? The app is coded in C#.
This answer is coming from my experience with developing Win32 apps using C++.
I can only think of two ways in which the app is being controlled -- one using OLE automation, using automation verbs and secondly inserting keyboard/mouse events into the system event queue. (I'm assuming that this app is not listening for any network originated commands). You can verify the first by checking the source code and using a debugger with some OutputDebugString calls. The second can only be detected by a malware scanner. Any COTS/free AV or MS security essentials should be able to identify a malware, unless of course it's written internally by a malicious employee.
Have you taken a look at the task manager process list and gone through them one-by-one to see if there's anything that looks suspicious? Can you run the app with elevated privileges? Then the OLE automation client, if one is present, won't be able to access the process.

Need emergency help with dw20.exe process? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
recently I have deployed asp.net application to production windows server 2008.
after 10-20 min, starts dw20.exe process (Microsoft.net error reporting shim), which takes almost all CPU available which cause to very slow response of my application.
No error no exception in Event Viewer.
I right clicked on the dw20.exe process and created the dump file to analyze what causing the issue.
Then I opened this file in WidDbg. run command .loadby sos mscorwks and get Unable to find module 'mscorwks'
It looks like I'm missing something or doing it wrong.
How to determine what cause an exception in application? how to analyze DMP file created?
Is it possible to stop this service?
Try adding ELMAH (http://code.google.com/p/elmah/) to the project so that you can grab the error info in an easier fashion.
When we get hit by rogue CPU, we use Sam Saffron's CPU analyzer to see what it is busy doing. Most times it turns out to be a bad regex (no, seriously; this bites too often for comfort).
The problem was that one of the method caused recursive loop.

When to develop using Powershell vs C#? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last month.
Improve this question
I'm just getting started in PowerShell and one of my sysadmins told me that Powershell can do as much as C# can for systems management, if not more.
Please forgive the ignorance of this question, but when would I use Powershell over C#?
1) PowerShell is good for relatively small well defined tasks, especially ephemeral one-day tasks and interactive tasks when you are coding right in the command line. If a task requires just a few lines of PowerShell code (and you know that because you know PowerShell well enough!) then launching a full C# project is often overkill.
2) C# is much better for large projects or where performance is critical. It is better for any project that will presumably require debugging and troubleshooting.
3) PowerShell and C# can perfectly work together. It is easy to call one from another. PowerShell is good for connecting .NET components. You can implement your complex and performance critical pieces in C# and then combine and glue those pieces together with PowerShell.
When I worked in the Windows build lab a LONG time ago (1997) the rule I was taught that if the code satisfies either of these two conditions write it in interpreted script, otherwise write it in compiled code:
there's more overhead than code (using/include lines, function declaration, etc)
there's a better than 10% chance that the code will change before it gets run again
From an infrastructure point of view, Hyper-V is getting huge in the virtualization market, it's outgrowing VMWare every year in terms of market share growth. Concerning SCVMM automation, if you want to leverage VMM functionality of managing multiple hosts running different hypervisors, VMM powershell interface is the only option.

Categories