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 7 years ago.
Improve this question
I have a cs page with a few methods. When I try to load that page it takes a long time. Is there any way to identify how long each method is taking to fetch data? Instead of debugging is there any way of capturing the time spans?
Any tool or any other suggestions?
Yes you can enable Tracing to check which event takes how much time.
set Trace = true in the Page directive.
Also you can write custom trace line
Trace.Write("Method 1 begin");
//Call you method thats taking time.
CalculateSomething();
Trace.Write("Method 1 begin");
And you can use stopwatch to check the exact time.
using System.Diagnostics;
Stopwatch St = new Stopwatch();
St.Start();
//Call your method
Trace.Write("Stopwatch " + St.ElapsedTime.toString());
St.Stop();
The Visual Studio Profiling Tools let developers measure, evaluate, and target performance-related issues in their code. These tools are fully integrated into the IDE to provide a seamless and approachable user experience.
Profiling an application is straightforward. You begin by creating a new performance session. In Visual Studio Team System Development Edition, you can use the Performance Session Wizard to create a new performance session. After a performance session ends, data gathered during profiling is saved in a .vsp file. You can view the .vsp file inside the IDE. There are several report views available to help visualize and detect performance issues from the data gathered.
MSDN REFERENCE
Related
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 3 years ago.
Improve this question
Me and my family use a command line application frequently. It gets tedious because sometimes the amount of chars entered can be a lot. My son asked me if it is possible to make it like a normal program. (He's 10, doesn't even know what a VCR or a touch-tone phone is lol.) Anyhow, I told him that someone would have to write a program for it. He say's he wants to. (I'm thinking I know who's going to take care of me and my wife in the future... lol j/k...) This will be a learning experience for both of us.
So, let's begin his career!
I'm not looking for someone to write the whole thing for us. We just need a good start.
How can we create a GUI for a command-line exe? (The exe is open source and is written in python but for now we'll stick with passing cmd's to the exe and reading its output.)
So we are looking for:
a textbox for our input, a few radio buttons for args, submit button and a clear button. I guess there should be a place to define the path to the exe.
Syntax: command --argument-abc --argument-xyz <textbox-data>
If no options are selected it should default to: command <textbox-data>
The 3 options we basically are starting with are: This way, That way or both
It should show the console output live as its running.
Here is a SS of where we want to start.
Preliminary Layout
Down the road we will package it together but I think this should be a good start to get us going. The exe has hundreds of different args that will be added over time on an options tab or what not.
We are using Microsoft Visual Studio 2017
Sorry for the rambling.
Oh and one last thing. Please point us to some good articles, how-to's, or anything that you think will help us learn what we need for this.
If you don't mind doing it in Python, then perrhaps PySimpleGUI will work for you.
There is a Demo program that does exactly this, add a GUI to the front-end of a command-line program.
OpenSource.com recently published an article that steps you through how to do this.
Just for fun I've duplicated the GUI you posed using PySimpleGUI. It is under 20 lines of code.
I recently combined my GUI python programs with PyInstaller. It produces a single .EXE file that runs and shows only my GUI window. The command I use instructs PyInstaller to hide the dos window.
pyinstaller -wF my_gui_program.py
PySimpleGUI Code and screen capture of window
With CommanUI you can specify your command line model and generate a GUI for it without coding.
Another alternative option is to use PowerShell to do this - the later versions have the .net framework built in, and can create user forms like in vb.net. If you have experience in vb.net, it should make it easier. As an extra advantage, PowerShell can usually use the same (or similar) commands as Command Prompt, so it should be familiar.
Take a look here for more information, however a quick google search for PowerShell GUI should be sufficient.
However, MikeyB is quite correct when he says that Python is a good language to learn - it's used in a lot of different areas in the industry (I still personally prefer vb.net though, I only looked at Python for a month).
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 6 years ago.
Improve this question
I'm doing some masks for SAP B1 using c#.
I'd need to know how to create a function that, automatically (for examples every 15 minutes), take some data and put its on a database.
The function is already done but how can I create the automatic execution in background?
Best regards and thanks in advance for the reply,
Lorenzo
Timer is what you need:
var timer = new System.Threading.Timer(
e => Method(),
null,
TimeSpan.Zero,
TimeSpan.FromMinutes(15));
This will call Method() every 15 minutes.
Timer info : https://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
You could use Timer like #AmbroishPathak suggested. Also, as mentioned in the comments, you can use the Windows Task Scheduler to run your script or executable. The advantage of this is that the process won't be running in the background while it's not doing work.
You can see the details of how to schedule a task here.
The following answer describes this as well: windows scheduler to run a task every x-minutes?
To summarize the accepted answer there, you create the task to run once a day. After that, you can double-click on the task to bring up its Properties window and go to the "Triggers" tab. Under "Advanced Settings" you should be able to set it to run every x number of minutes.
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 6 years ago.
Improve this question
I am trying to automate the cleanup of legacy/heritage code and I can identify current resources in use from IIS logs but server side pages like .ASP and .PHP have include chains which I would like to be able to identify via code (C#)
In order to narrow the question down as it was too broad ...
OS - Windows 10
Web Server - IIS
Preferred language - C#
Example - any IIS served website
I have code that reads IIS log files where I have identified all static served resources including the initial .ASP or .PHP pages.
I required some accompanying C# code to also detail any .ASP or .PHP included files that were processed on the server and therefore do not appear in the IIS logs.
As it happens I have found the solution and provided an answer below.
I hope this is enough detail to take this off 'On Hold'
Many thanks to #Progrock for pointing me to checking last accessed time for files in target folder. This is what I had to do.
Ensure capturing last accessed time is being set by Windows (see Directory.GetFiles keeping the last access time)
Process.Start("fsutil", "behavior set disablelastaccess 0").WaitForExit();
Also need to restart IIS to stop any cached in memory files
Process.Start("IISRESET").WaitForExit();
A refresh on FileInfo needs to be performed to ensure you get the correct last accessed time (see How can System.IO.FileSystemInfo.Refresh be used).
This resulted in the following code ...
var start = DateTime.UtcNow;
Process.Start("fsutil", "behavior set disablelastaccess 0").WaitForExit();
Process.Start("IISRESET").WaitForExit();
//do work that will access folder. i.e. access IIS web pages
var files = Directory.GetFiles(iisPath, "*.*", SearchOption.AllDirectories).ToList();
files = files.Where(x =>
{
var fileInfo = new FileInfo(x);
fileInfo.Refresh();
return fileInfo.LastAccessTimeUtc >= start;
}).ToList();
I can use this list of files to identify all .ASP and .PHP and any other files that were accessed via the IIS server on page requests.
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 want to read sms from my GSM modem.
I wrote C# code.
This code run when I click start button.
I want to my program read sms when received, not click button.
thanks.
Your program is keyed to activate when you press a button, some method is called. You need to call this method when SMS data is received instead. This could be done using threads (SMS thread and main thread showing data) although it could just as easily be done using a cycle. In pseudo code:
while (don't quit) {
display page;
check for sms data;
sleep for small time to allow other OS programs to run also;
}
This is a "tight loop" and can use excessive amounts of CPU time depending on the code of the actual steps. For a tight program loop one simple method is to apply some sort of sleep method.
There are other ways to do the same thing, visitor pattern could probably be used, threads, etc...
It seems that you are only lacking the cycle. Your programs is probably more like:
while (don't quit) {
display page.
wait for button press.
}
although that flow wouldn't be obviously apparent at first glance without studying your program flow.
If you are using triggers (the button press is probably a trigger) you can trigger on a timer that fires as often as you want (100ms, 1 second, whatever) that checks for SMS data when fired, if there is SMS data it updates the form.
Many, many ways to do this. A quick Google for "program flow" doesn't find any useful links at first glance that would explain the many ways you could do this. Perhaps looking at other's code would help. I've often searched open source repositories for code I could look at to see how someone else did something.
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 9 years ago.
Improve this question
I need to learn a certain programming subject and I don't know where to start, would like your help.
This is what I need do do, I have a user form (UI) and the user enter "Rules" in the form of:
if operator(obj1) then assign(obj1,string)...
I take this rules, and translate them into actual code, and I want to put that code somewhere in a function/my code.
for example:
main {
UI...
/* when we reach here, means the user done writing rules */
/*Function that translate the user rules to actual code */
translate();
for {
/* This is where I want to put the code after translation */
}
}
How do I put the code inside the loop (or anywhere else for that matters) after the program started running?
I ofcourse don't look for an actual answer, more to give you an idea what I need so you can refer me to a certain subject to study about.
I presume, you are in process of creating a custom rule engine, which has the capability of validating your rules on fly. Within my ability, you need to start reading c# scripting, code generation, dynamic loading or reflection etc are some to start with.
To give a kick start, following are some of the step which I can think off;
Grab the rule definition (xml or csv)
Write a small helper which will read rule entries from the definition and convert it into
c# source code. This is similar to c# scripting.
On successful completion of (2), create a dll out of the source code
Now reflect/dynamically load the dll from (3) to where ever you wanted to validate the rule.