The following code prints out the first and second arguments passed to a console application. class Program { static void Main(string[] args)//string[] args is the parameter used to pass arguments to a program { Console.WriteLine(args[0]);//first argument Console.WriteLine(args[1]);//second argument } } Getting the arguments to the program can be done in several ways: In Visual Studio: [...]
Posted in:
C#
by
admin
/
No Comments
While the using directive can be used to create an alias for a type which appears to be a pretty cool replacement for typedef, this article brings out some interesting and important differences. Mainly, the need to define the alias in every page and the lack of a single header definitions file. Because of that [...]
Posted in:
C#
by
admin
/
No Comments
Extension methods allow us to extend an existing type without modifying the original type. This means we can extend an existing type without re-compiling. So whats the use of that? We have a project with types spread amongst DLL’s all over the place. Rather than having to locate the correct DLL, we can package our [...]
Posted in:
C#
by
admin
/
No Comments
Many of the default windows services are housed within a “Service Group”. This group allows one to specify a specific service start order in the registry HKEY_LOCAL_MACHINE\CurrentControlSet\Control\ServiceGroupOrder. Services do not have to be in a group. Services that are not in a group are started after the groups have been started. Go to HKEY_LOCAL_MACHINE\CurrentControlSet\Services to [...]
Posted in:
C#
by
admin
/
No Comments
File locking – yet another reason a file is a poor substitute for a database. File Locking is a mechanism to restrict concurrent access to a computer file by only allowing only one user or process to perform file I/O at a time. The infamous “Access Denied” can be caused by file locking. This means [...]
Posted in:
C#
by
admin
/
No Comments
Volatile is not about what will happen, but what can happen. Volatile stops optimization techniques performed by the compiler, by the runtime system, or by hardware that reorder instructions. Reordering instructions can lead to unpredictable results in multi-threaded programs. The following MSDN example for volatile isn’t likely to produce any ill effects. As simple as [...]
Posted in:
C#
by
admin
/
1 Comment
Ever had the need to communicate between two winform programs, two console programs? That is an example of Interprocess Communication (IPC). When you start an exe a process is started and can contain one or more threads. If the stop the process, all the threads stop with it. Communication between thread boundries is often done [...]
Posted in:
C#
by
admin
/
No Comments
Form.Close is superior to Form.Dispose. Both methods will call dispose, but that’s where the similarities end. Form.Close has the following benefits over Form.Dispose: 1. Fires the Form.Closing and Form.Closed events. 2. Allows one to cancel the closing event. Unless you want to ensure the loss of these functions stick to using Form.Close. I created a [...]
Posted in:
C#
by
admin
/
No Comments
A race condition occurs in multithreading when 2+ threads modify the same object in an unsafe way. Think nascar. If two cars try to share a lane its just fine, but if two cars try to share a lane in the same place…crash. Also in Nascar, a racer can come running up on you at [...]
Posted in:
C#
by
admin
/
2 Comments
Vista protects the C root from programmatic modification. “But my favorite and most awesome programmer gets it to work”. Yes, it’s not because of their l33t hax skillz. The write protection is provided by UAC. Disable UAC and you enable writing to the C root. Personally, I praise Microsoft for trying to force programmers to [...]
Posted in:
C#
by
admin
/
No Comments