Showing posts with label Release. Show all posts
Showing posts with label Release. Show all posts

Tuesday, April 10, 2012

How to modify/create build configurations in Visual Studio?



In project life cycle you might need to create or access various builds like Development, Testing, User Acceptance Testing, Production etc. Visual Studio provides Configuration Manager Toolbar to change, create or access builds. By default solution has two builds Debug and Release.

Typically debug build is used to debug and detect errors (compile-time and runtime) from solution or project. Once project or solution development is complete and ready to deploy than project or solution should be built in Release mode. Release builds enables code optimization and enables fast execution of program.

You can also change or create new configuration using configuration dropdown available on standard toolbar.


For add or change configuration you can select configuration manager from any of the drop down. If sometimes configuration or platform drop downs are not visible on standard tool bar of visual studio in such case you can add those externally by clicking on customize menu item of tools menu.


The Configuration Manager Dialog will appear.


Similarly you can open Configuration Manager Dialog from right click of your solution and click on Configuration Manager (below image).

You can change or edit configuration and platform for each project under solution.


The same configuration used to develop application to choose correct config file or connection string or other configuration specific task. Let’s have a look on below code.

#if DEV
        Console.WriteLine("DEV Configuration...");
#elif QA
        Console.WriteLine("QA Configuration...");
#endif

As per above code, based on selected configuration either DEV or QA the appropriate code will execute. One more thing, by default Debug and Release configuration added with project and during compilation it will create Debug and Release folder under Bin folder located at solution folder. If we added new configurations in our case DEV and QA then respective folder will get created under solution’s Bin folder and respective resource and assembly will be added to that.



Monday, December 5, 2011

Mutex - Threading



Mutex ensures only one thread can enter particular section. Mutex is similar to lock statement the only difference is that Mutex can work across multiple processes while lock can work only for multiple threads. Mutex ensures only one process (application) can run at a time. Mutex is slower than lock. We can use WaitOne method to acquire lock and ReleaseMutex to release lock.

There are two types of mutex available, named and unnamed. Unnamed mutex are called as local mutex and available within your process. Only threads inside your process can access it. While named mutex are visible throughout the operating system and multiple processes can be able to access it. Checkout Mutex page on MSDN for more information.    

Let’s understand with simple example.

public static Mutex mutex = new Mutex();
public static void DoWork()
{
        mutex.WaitOne();

        Console.WriteLine("Thread {0} has entered", Thread.CurrentThread.Name);

        Thread.Sleep(2000);

        Console.WriteLine("Thread {0} is leaving", Thread.CurrentThread.Name);

        mutex.ReleaseMutex();
}
public static void Main()
{
       for (int i = 0; i < 3; i++)
        {
            Thread t1 = new Thread(new ThreadStart(DoWork));
            t1.Name = "Thread " + i.ToString();
            t1.Start();
        }
}     


As demonstrated in above code, WaitOne method requests to acquire a lock and ReleaseMutex method request to release lock. Mutex can only be released by the thread that acquired it. The main method creates three threads one by one and tries to access DoWork method. DoWork method implements mutex so only one thread at a time will able to access.