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.

Obfuskacja - Java code obfuscation tool, June 17, 2009

Posted by artiko in: Java , Software , 2comments

Nowadays, applications written in Java or C # fairly easily zdekompilować and sometimes get cleaner code. Of course, long ago devised ways of hedging against the :)
One very simple and is just obfuskacja, that is obfuscation of code. It involves modifying the code or bytecodu that it was not possible to understand it later. After a detailed description refer to the Wikipedia page - pl.wikipedia.org / wiki / Zaciemnianie_kodu .
After a short search the web, I found a project called ProGuard , which allows you in a really fast way to obfuscate code, reduce the volume of files and to optimize the object code. It can be run from the command line, but also has a GUI. Personally I prefer the GUI, because if you use the console version have to create a configuration file for each package. The application is written in Java, making it multiplatform.
The program tab in the Input / Output just add the jar file our application, the resulting file, and, very importantly, the library files, which are references in our code. The next tab, you can leave the default values, click the Process in the Process! and after a while we get an output file, protected from those who would look to him :)
I am on the first use I found the error
Warning: javax.swing.JFrame: can't find superclass or interface javax.swing.TransferHandler$HasGetTransferHandler

The solution is simple, the Information tab, simply uncheck the box Skip non-public library classes and class members.

Grouping objects displayed Java3D May 13, 2009

Posted by artiko in: Java , add a comment

To solve a common problem: the canvasie display dozens of objects, some of which is static at run-time, part of the dynamically updated. What to do to avoid having to remake reload all objects in canvasie and avoid blinking?
The answer is simple if you use the class to which javax.media.j3d.BranchGroup addChild (Node arg0) you can just add 3D objects. Of course all of this group can easily be transformed.
If we add to one group of static objects in the display, the second refreshed enough that during the execution of the program will refresh only the second group. This can be done using the method detach () for the group, and then reload the content and adding it to canvasu, or parent group.