jump to navigation

Execution time of code in C # February 6, 2010

Posted by artiko in: C # , Programming , add a comment

Often, for diagnostic purposes - we want to benchmark to measure code execution time of a program / algorithm. A simple method is:

  Now ; DateTime start = DateTime. Now;
 / / Our code
 Now ; Stop = DateTime DateTime. Now;

 start ; TimeSpan ElapsedTime = stop - start;
 ( "Czas wykonania: " + elapsedTime ) ; MessageBox. Show ("Execution time:" + ElapsedTime); 

You can do it even nicer by using the System.Diagnostics class:

  Stopwatch stopwatch = new Stopwatch ();
 ( ) ; stopwatch. Start ();
 / / Our code
 ( ) ; stopwatch. Stop ();
 ( "Czas wykonania: " + stopwatch . ElapsedMilliseconds ) ; MessageBox. Show ("Execution time:" + stopwatch. ElapsedMilliseconds); 

How to read path from OpenFileDialog January 12, 2010

Posted by artiko in: C # , add a comment

To read the path, which is indicated by the OpenFileDialog file you can use:

  Path . GetDirectoryName ( openFileDialog . FileName ) System. IO. Path. GetDirectoryName (openFileDialog. FileName) 

How to choose a target architecture, build the project in Visual C # 2008 Express, January 6, 2010

Posted by artiko in: C # , Programming , 1 comment so far

When used in Visual C # 2008 Express Edition ADO.NET to handle xls files I received the error "Provider 'Microsoft.Jet.OLEDB.4.0' not registered on the local computer.". Let me add that I'm using Windows 7 x64. As I read, there are no problems with the x86 versions. So I decided to compile the project only on the x64 architecture.

There was a problem: how to change the build target architecture? Under the toolbar is an option to change it, but by default it is not available. How do I enable it? The answer is trivial, just in Tools-> Options select Show all settings, which by default is unchecked. Then in the Projects and Solutions section to enter into General and select the Show advanced build configurations. The result is access to many functions, including the possibility of defining.

The solution I found on this blog. There are also screenshots of the next steps.